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.

Cheers,
Michael

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.

commented: Thanks Pritaeas! +4

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?

Michael

Benefit? Ease of use, nothing else.

Understood, cheers fella

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.