I have a variable localStorage.lastUpdate which stores a timestamp such as 1332237161. I need to pass that timestamp to the server which im trying to do by the line below with:
listener.php?q="+localStorage.lastUpdate
I also have another variable, localStorage.numUpdates that should receive the number of updates back from the server. I am confused whether I can use the below code with xml to run commands. Can my server side php file do something of the following
echo "localStorage.numUpdates=".$currentCount.";";
echo "localStorage.lastUpdate=".time().";";
where it would take affect on my localStorage variables in the javascript portion?
function contactServer()
{
if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest();}
else{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
xmlhttp.responseText;
}
}
xmlhttp.open("GET","listener.php?q="+localStorage.lastUpdate,true);
xmlhttp.send();
}
Any information would be helpful, thanks!
That won’t work (and don’t use
eval()!).But you can just output JSON in your PHP script:
And in your JavaScript code: