Search code examples
javascriptajaxcachingbrowsernook

Ajax Request Not Loading New Data


My application uses polling to update the status of a music player. I'm using setInterval to make an Ajax call every half a second to do this. It works on many browsers (Chrome,Firefox, Safari... ) except the Nook color's browser. When the page loads it updates the correct information, but after that it always loads the same information. This was confirmed using alert. Here's the original code

function getStatus() {

request = new XMLHttpRequest();

request.open("GET", SOME_URL, true);

request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

request.onreadystatechange = function () {

if (request.readyState === 4 && request.status === 200)

updateStatus(request.responseText);

};

request.send()

}

setInterval(getStatus, 500);

Any ideas why it is always loading the same info (the info it fetches initially) ?

Also: it only loads the most current information if you clear the cache. This Nook was rooted and also had Firefox and it would work just fine. It's the Nook native browser that is doing this (rooted or unrooted).


Solution

  • Internet Explorer has a weird quirk where it caches AJAX content. I imagine you are seeing the same issue in the Nook browser. The solution is to add a "cache buster" parameter, which is basically just a random parameter so the URL is treated freshly:

    "SOME_URL?random=" + Math.random()