views:

80

answers:

1

I must admit, this is my first post on this site, so I apologise in advice if I do something wrong (formatting etc).

Anyway, I'm creating a kind of mmo using javascript (and jQuery), and so far everything is running fine in Chrome, Safari, Firefox, etc. However, I've found that somewhere along the line, Internet Explorer crashes.

By reproducing the crash I've narrowed it down to this code:

function getUpdates(){
var data={uid:playerName,area:1,mid:lastMessage};
$.ajax({ 
    url: "getUpdates.py", 
    timeout: 32000,
    data: data,
    type:"GET",
    complete: function(obj, textStatus){
            //handleUpdates(obj);
        getUpdates();
        }
    });
}

Which is supposed to poll for updates over a long time. However, in IE after one reply this code gets stuck in an infinite loop, which will crash the browser. It doesn't seem to crash after every reply, only if there is no server response.

Note, the line that says "complete:..." has been tried as:

success: function(...){getUpdates();...},
error: function(...){getUpdates();...}

with the same problem occurring.

+3  A: 

IE is returning the AJAX call instantly from a cache.

You should add a random parameter to the URL to force IE to ignore its cache, like this:

url: "getUpdates.py?RandomNumber=" + Math.random(), 

(You can also use new Date)


Also, you should probably check for updates a little more slowly by adding a 5 second delay:

complete: function(obj, textStatus){
        //handleUpdates(obj);
    setTimeout(function() { getUpdates(); }, 5000);   //milliseconds
}
SLaks
+1 - I didn't consider that it was cached, so turning off the caching may resolve this. I just assume caching is off for ajax calls, bad assumption.
James Black
thanks, I tried this and it worked like a charm! I didn't realise browsers would cache AJAX calls, thanks.
Sylvan