Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Loading ajax content - caching woes


Reply


8 Posts   3381 Views

Avatar
Hamish

Community Member, 712 Posts

11 May 2009 at 2:00pm

Hi all,

I've having an issue with cached content loaded by Ajax.

I'm using jQuery and have disabled browser caching for jQuery ajax requests. I've disabled the SS cache (with HTTP::set_cache_age set to 0). I have cleared the browser cache and rebuilt/flushed. Despite this, content loaded via ajax seems to be coming from a cache. I have to append the ajax query with ?flush=1 to force the response to be updated.

Anyone got a better way?

Thanks!

Avatar
Hamish

Community Member, 712 Posts

11 May 2009 at 2:03pm

By the way, the Wiki says that:

"Ajax requests are never cached."

But that is not what I'm seeing.

Avatar
david_nash

Community Member, 55 Posts

12 May 2009 at 2:44pm

Edited: 12/05/2009 3:05pm

Are you using Internet Explorer? According to this page:

http://docs.jquery.com/Ajax/load

...IE caches the requests:

Note: Keep in mind that Internet Explorer caches the loaded file, so you should pass some extra random GET parameter to prevent caching if you plan to call this function more than once

Even if not you could try appending a random GET string to the URL you're calling via AJAX and see if that helps.

Avatar
Hamish

Community Member, 712 Posts

13 May 2009 at 8:59am

Thanks David, that occurred to me, but I didn't think it would be necessary. I was using FF3 to see the requests.

Avatar
david_nash

Community Member, 55 Posts

13 May 2009 at 10:17am

No worries - did that fix it or was there some other solution?

Avatar
Hamish

Community Member, 712 Posts

13 May 2009 at 10:20am

Yes, it seems to have done the trick.

Avatar
majo

Community Member, 2 Posts

9 August 2010 at 4:43am

I have a problem with Ajax in IE 8 Method does not work load. I try to add a URL to a random number

$("#test").load('My_Controller?random=' + Math.random()*99999,data,function(vystup){
var obj = jQuery.parseJSON(vystup);
alert("Hello!!!");
..........


but still nothing. In FF, Safari, Chrome works, but unfortunately Explorer Sun You have some additional advice on how to fix it

Avatar
web2works

Community Member, 50 Posts

26 September 2010 at 1:27am

Hi, would you be able to post some example of your ajax code. I am wanting to do a something like this:

$('input.action').click(function() {
$(this).parent().parent().find("form").fadeOut();
$(this).append('<img src="images/ajax-loader.gif" class="loaderIcon" alt="Loading..." />');

var Name = $('input#name').val();
var Email = $('input#email').val();
var Comments = $('textarea#comments').val();

$.ajax({
type: 'post',
url: 'sendEmail.php',
data: 'Name=' + Name + '&Email=' + Email + '&Comments=' + Comments,

success: function(results) {
$('img.loaderIcon').fadeOut(1000);
$('.content').html(results);
}
}); // end ajax
});

Thanks for any help you can advice me on.