I have a page that uses an ajax function to get updates from another page.The function uses the user's id, which is retrieved from a session variable to find any updates, which is then displayed in a "Updates" div. While my script is working currently, i find myself wondering if i could retrieve the userid stored in the session variable in my Ajax page instead of passing the userid through the ajax function. Are there any advantages and/or disadvantages to passing the userid through the ajax function instead of accessing it directly in the ajax script?
My Ajax function:
function FetchUpdate()
{
var userid= <?php echo $_SESSION['UserID'] ?>;
$.ajax(
{
type:"POST",
url:"getupdates.php",
data:{userid:userid}
})
.done(function(data){
$("#Updates").html(data);
setTimeout(FetchUpdate,1000*60);
})
}
Ajax page(getupdates.php)
session_start();
$userid=$_SESSION['UserID'];
//fetches updates
//echos updates