views:

1027

answers:

2

Hey,

I am currently doing the same ajax request using jQuery every 2sec. For some reason, on IE8 it only work the first time. Each following request automatically seems to go to the onSuccess function, with the same result as the first request.

The same code work perfeclty on FF3 and Chrome.

Is anybody aware of that bug and how to hack around it? Or am I simply doing something wrong?

+6  A: 

IE has a caching feature... it's possible that it has just cached your request. Make sure you append something like a random number to your query string, like so:

var url = "/yoururl.html";
url = url + "&random=" + Math.random();
Jason
That worked perfectly. Thank you for you fast answer Jason.
Zwik
if this helped you, plz accept as answer! thx
Jason
sry ^^, (I'm new here)
Zwik
no worries :) we <3 n00bs here
Jason
An alternative solution is to simply use POST; POST requests shall not be cached (sayeth the spec).
Cide
+1  A: 

Just so you know $.ajax has a cache attribute that, when set to false does exactly what Jason is doing, namely, includes a random parameter that means no requests get cached. It's a little more elegant than doing it yourself

brad
Oh! really good to know hehe. Thank you brad :)
Zwik