jQuery Ajax caching
I make a few Ajax calls to get files via jQuery like so:
$.ajax({
url: "/resx.mvc",
data: {
virtualPath: options.virtualPath,
keys: options.keys,
global: options.global
},
cache: true,
开发者_JS百科 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 being sent, and making my ASP.NET send back an expires header on its response with -1:
Pragma: no-cache
Cache-Control: no-cache
How do I tell jQuery not to issue no-cache?
beforeSend takes an ajax object (XmlHttpRequest object) which you can use to manipulate the request header. Below is an example of setting a 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));
}
});
精彩评论