JQuery Ajax Caching

I make several Ajax calls to get files through jQuery as follows:

$.ajax({ url: "/resx.mvc", data: { virtualPath: options.virtualPath, keys: options.keys, global: options.global }, cache: true, success: function (values) { $.extend(assignTo, values); }, dataType: "JSON", traditional: true }); 

When I look at the request in Fiddler, I see that these two headers are sent, and my ASP.NET sends the expires header back to its response with -1:

 Pragma: no-cache Cache-Control: no-cache 

How to tell jQuery not to release no-cache?

+6
jquery caching
source share
1 answer

beforeSend accepts an ajax object (an XmlHttpRequest object) that can be used to control the request header. The following is an example of setting the header in your request using the ajax object returned in the callback:

 $.ajax({ type:"POST", beforeSend: function (request) { request.setRequestHeader("Authority", authorizationToken); }, url: "entities", data: "json=" + escape(JSON.stringify(createRequestObject)), processData: false, success: function(msg) { $("#results").append("The result =" + StringifyPretty(msg)); } }); 
+6
source share

All Articles