如何启用缓存jQuery的阿贾克斯 [英] how to enable caching in jquery ajax
问题描述
jQuery("#divProviders img").click(function (e) {
//alert(jQuery(this)[0].nameProp);
document.getElementById("TxtProvPic").value = jQuery(this)[0].getAttribute("src"); //jQuery(this)[0].nameProp;
$.ajax({
type: "GET",
url: "Services/TeleCom/EVoucher.aspx",
data: "ExtFlag=GetProducts&AjaxFalg=SpecialRequest&prov=" + jQuery(this)[0].id.replace("img_", "") + "&pcat=" + document.getElementById("Txhhc").value,
beforeSend: function () {
document.getElementById("DivProducts").innerHTML = "";
document.getElementById("DivLoad").innerHTML = "<img alt='' style='margin-left:300px;margin-top:80px;position:absolute;' src='App_Themes/VivaTheme/images/bigloading2.gif'/>";
},
cache: true,
success: function (data) {
var StrResponse;
StrResponse = data.split('@@@');
EvoucherFillProductsRes(StrResponse[0]);
},
error: function (xhr) {
alert("responseText: " + xhr.responseText);
}
});
function EvoucherFillProductsRes(res) {
var slices = res.split("*******");
document.getElementById("DivProducts").innerHTML = slices[0];
document.getElementById("DivMenu").innerHTML = slices[1];
document.getElementById("DivLoad").innerHTML = "";
jQuery("#BrowsableTwo").scrollable({
prev: 'a.prodprev',
next: 'a.prodnext'
}).navigator();
}
我有这样的功能,当我点击到内容设置为一个div的innerHTML我设置链接缓存:真正的
在jQuery的阿贾克斯,但如果我再次点击属性没有缓存显示AJAX功能的链接仍然会在服务器端,达到了相同的内容我很困惑是缓存:真正的
真正使缓存和我应该怎么办使它工作?
I have this function when i click to the link a content is set to a div innerHTML i set cache:true
attribute in the jquery ajax but if i click again to the link no cache is displayed the ajax function is still going to the server side and reach for the same content i am confused is cache:true
really enable cache and what should i do to make it work ?
推荐答案
缓存:真正的
是默认的,不总是从缓存中的内容。在浏览器上的项的高速缓存能力取决于:
cache:true
is the default and does not always get the content from the cache. The cache-ability of an item on the browser is determined by:
-
的响应头从原始Web服务器返回。如果标头指示 内容不应被缓存,然后它不会。
The response headers returned from the origin web server. If the headers indicate that content should not be cached then it won’t be.
一个验证器,如了ETag或Last-Modified头必须是present的响应。
A validator such as an ETag or Last-Modified header must be present in the response.
从此链接
缓存:假
还有一个用例无论该内容是否被缓存或不总是加载来自服务器的内容。
cache:false
has another use case to always load the content from server regardless of whether that content is cached or not.
这里的要点是:缓存能力由服务器决定和缓存:真正的
或缓存:假
的 $。阿贾克斯
只是以确定是否寻求缓存的响应与否。
The point here is: the cache-ability is determined by the server and cache:true
or cache:false
of the $.ajax
is just to determine whether to look for the cached response or not.
这篇关于如何启用缓存jQuery的阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!