Set Session Var With Ajax
I want to create a session var. I have a web page with some tabs that don't recharge when I active one another. So, I don't know how to set my session var. Indeed, my first tab wil
Solution 1:
Ajax
$.ajax({
type : 'POST',
url : './session.php',
dataType: "json",
data: data,
success : function(data){},
error : function(){}
});
PHP
<?php
session_start();
$_SESSION['data']=$_POST['data'];
echo$_SESSION['data'];
?>
});
Data is what you send through a POST, now echo can return that data or a different amount of data to your Ajax request as a response.
Using, $.post():
$.post({url:url,data:data,success:success,dataType:dataType});
However, $.ajax(), is much much better, since you have more control over the flow, and if success do this etc.
Post a Comment for "Set Session Var With Ajax"