Reputation: 1827
I have the following:
myfunc = function(url, callback, etc...) {
$.ajax({
type: 'GET',
url: url,
etc.});
}
function changeDivThis(data) {
$('#this').html(data);
}
function changeDivThat(data) {
$('#that').html(data);
}
and I call the ajax get function twice in succession:
myfunc('/getData?mode=THIS', changeDivThis, etc...);
myfunc('/getData?mode=THAT', changeDivThat, etc...);
and the result is that some significant fraction of the time, say 20% of the time, the div with id='this' will get populated with the data that was returned by the call for THAT. And when I look at the app server logs, I see some unexpected stuff, like only one request.
When I run in Firebug, the bug never occurs, everything is fine. I noticed that Firebug considerably slows down browser operation, so I'm assuming this is a clue to the cause, having something to do with concurrency, e.g. the second call returns from the server first on some occassions, and the browser thinks it's the response to the first call. Correct?
So in my limited experience with AJAX, I thought it supported throwing several concurrent requests at the server and then it sorted out the responses in whatever order they returned. This problem leads me to believe that AJAX (or my version of Firefox = 3.6.24/jQuery = 1.4.4) sees two requests to the same url as the same even though they both have different parameters.
I saw this highly-ranked page on Google: http://blogger.forgottenskies.com/?p=173 which makes me believe I'm not alone in experiencing this issue.
Thanks for any insights.
Upvotes: 2
Views: 1302
Reputation: 6385
Try adding cache: false
into your options you pass to your $.ajax()
call. I thought it only affected IE, but...
See cache option here: http://api.jquery.com/jQuery.ajax/
Upvotes: 1