Saturday, October 13, 2012

How to prevent Caching in AJAX requests


Below steps you can perform to prevent caching in AJAX calls.
              To prevent the response from being cached you can set preventCache flag to true while making dojo request.
            var getContentCallback = function (contentAliases) {
            var contentUrl = servletPath + "/content";
            var xhrArgs = {
                        url:contentUrl,
                        handleAs:"json",
                        preventCache: true,
            content:{
                contentType:"Content",
                contentAliases:dojo.toJson(contentAliases)
            }
        };
        var deferred = dojo.xhrGet(xhrArgs);
        return deferred;
    }

When the preventCache will be set to true it will append dojo.preventCache query parameter to the url before making request so in that case it will take the <portlet:resourceURL/> and append the dojo.preventCache query parameter and the value of dojo.preventCache parameter will change every time the xhr call will be made so server will always return the full response.

No comments:

Post a Comment