Jump to:

23355 Posts in 17702 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Loading ajax content - caching woes

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

Page: 1
Go to End
Author Topic: 3243 Views
  • Hamish
    Avatar
    Community Member
    712 Posts

    Loading ajax content - caching woes Link to this post

    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!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Loading ajax content - caching woes Link to this post

    By the way, the Wiki says that:

    "Ajax requests are never cached."

    But that is not what I'm seeing.

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: Loading ajax content - caching woes Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Loading ajax content - caching woes Link to this post

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

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: Loading ajax content - caching woes Link to this post

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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Loading ajax content - caching woes Link to this post

    Yes, it seems to have done the trick.

  • majo
    Avatar
    Community Member
    2 Posts

    Re: Loading ajax content - caching woes Link to this post

    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

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Loading ajax content - caching woes Link to this post

    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.

    3243 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.