Search code examples
jqueryajaxcachingjeditable

Jeditable retrieve cached results using LoadURL option


I'm using the jQuery jEditable plug-in to edit some part of a website.

As the text use Textile format, I use the LoadURL option to bring in the unformatted data.

The problem arise when the user edits some text, and then go back to re-edit it, the ajax call brings back the cached result.

I've tried to add a random parameter, but the same random number is added, so it is useless.

        $(".edit").livequery(function(){$(this).editable("<%=Page.ResolveUrl("~/savetext.aspx") %>", {
             loadurl   : '<%=Page.ResolveUrl("~/gettext.aspx") %>?Rnd=' + Math.random().toString(),
             type      : 'textarea',
             cancel    : 'Cancel',
             submit    : 'Save',
             indicator : 'Saving...',
             rows      : 4,
             tooltip   : 'click to edit'
            });
        });

Is there a way to tell jEditable to add a random parameter in each call?


Solution

  • I'm seeing this too, but only intermittently. I realised that in my equivalent to gettext.aspx (which in my case is PHP code), I was not setting response headers to prevent browser caching. I have added something like this and it seems to be behaving better:

    header("Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-cache, must-revalidate" );
    header("Pragma: no-cache" );
    

    I'm no asp developer, but after searching around I think an equivalent might be:

    HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
    HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetNoStore();