Reputation: 71
I have a xml file called 'images.xml'. It is modified by php script every time some one uploads new image on to the server. I also go thru that file using ajax.
xmlhttp.open("GET", "images.xml", true);
xmlhttp.onreadystatechange = handleStateChange;
xmlhttp.send(null);
But for some reason "xmlhttp.responseXML" stores version of that file as it was at the beginning of current user's session. So if user uploads new image, even though xml file gets updated by php, ajax retrives version of that file from before update.
ps
I'm new to ajax, so I might be missing somethin obvious.
Upvotes: 1
Views: 80
Reputation: 1933
Probably because of the cache. You need to append a query parameter to the URL, so that it's always different.
A common practice is to append the current UNIX timestamp, in milliseconds in this case.
var url = 'images.xml?nocache=' + Date.now();
Upvotes: 3