ello ello,

I'm currently calling a file using JQuery but every so often (very randomly) Google Chrome would crash (Just the tab, not the browser). Soooo I began investigating and discovered that browsers cache AJAX calls? This would mean that the tab would be using a stupid amount of memory that would of course cause issues. I also discovered that I should be aborting all 'AJAX' calls before I call this primary one. How on earth..?

Anyway, to see if this was the case I added a random number to the query string on the file call:

function reloadResponses() {
    $('#divid').load('load.php?creatorid=<?php echo $topicInfo['id']; ?>&RandomNumber=' + Math.random());                    
setInterval(reloadResponses, 10000);

Now - the issue hasn't reoccured as of yet (I'm still waiting), but I'm very interested and trusting of the feedback from this community. Any suggestions? I would also be glad to read any suggestions for resources regarding tidy and efficient AJAX calls - the ones I seem to be pulling up haven't been updated since the birth of christ himself.


3 Years
Discussion Span
Last Post by mmcdonald

I don't know how to do it in JQuery, but the XMLHTTPObject has an abort method. Im sure you can look into jquery's version of that method.

Also, look into using the Date() object to get a random number instead of Math.random() as it's possible (however unlikely) that you get the same result twice.


If instead of load you use ajax then you can specify cache:false and a number will be added automatically.

Votes + Comments
Thanks Pritaeas!

Yeah, as Pritaes said, use $.ajax and add the option cache:false. What jQuery does in this case is adds a random, unused number on the end of the query string. That effectively changes the URL, and as such the browser performs the request without caching. Something like this: $.ajax({url: 'url', cache: false, success:function(data) { console.log(data); } })


Whoops - totally missed this topic, sorry!

I have done this and it seems to be working perfectly. Sorry for not getting back to you.

I must ask, what's the benefit of using cache: false and AJAX over JQuery .load and a random number and/or a timestamp?


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.