Today my colleague, Al-Amin Rubel, faces a interesting (but very common of course) problem –

“Pages are not being reloaded/ refreshed after contents are updated by AJAX” that means AJAX request always returns/responses same data from server although data has already been changed. But, more interesting matter is in mozilla FIREFOX is working fine whereas I.E (internet explorer) showing same output.

After debugging a lot, it was clear that whenever request URL of ajax is exactly same as previous request, it loads the output from cache.

Solution:

So, perhaps the best solutions is to change the url every time. Don’t afraid, this is very simple, just add a url variable with random value using random() function.

Example:

Suppose, your AJAX request URL is – “ajaxresponse.php?name=xyz&res=123”

Then change it by adding a variable with random value – like

‘ajaxresponse.php?name=xyz&res=123&rnd=’+Math.random(10);

That’s it, solved!

This is because browser takes the url as a new request (url) every time.

Advertisements