JQuery Ajax causes Internet Explorer to crash?

I must admit that this is my first post on this site, so I apologize for the advice if I do something wrong (formatting, etc.).

Anyway, I create mmo using javascript (and jQuery), and so far everything works fine in Chrome, Safari, Firefox, etc. However, I found that somewhere along the line of Internet Explorer crashes.

When playing the crash, I 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 should poll updates for a long time. However, in IE, after one answer, this code gets stuck in an infinite loop, which will lead to a browser crash. It does not seem to crash after each response, only if there is no server response.

Note. A line that says "complete: ..." has been checked as:

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

with the same problem.

+4
source share
1 answer

IE instantly returns an AJAX call from the cache.

You must add a random parameter to the url to force IE to ignore its cache, for example:

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

(You can also use new Date )


In addition, you should probably check for updates a bit slower by adding a 5 second delay:

 complete: function(obj, textStatus){ //handleUpdates(obj); setTimeout(function() { getUpdates(); }, 5000); //milliseconds } 
+12
source

All Articles