[英]AJAX response is cached when using DOJO
I am using the below DOJO functionality for AJAX call. 我正在使用以下DOJO功能进行AJAX调用。 But unfortunately the respose for a particular request is cached.
但不幸的是,缓存了特定请求的保留。 And even if I change the code in servlet side, its is not reflected for the cases where I have tried earlier.
即使我改变了servlet方面的代码,也没有反映出我之前尝试过的情况。 I guess the reponse is cached.
我猜这个反应是缓存的。 I am using Tomcat server.
我正在使用Tomcat服务器。 Can any one please help?
任何人都可以帮忙吗?
<script type="text/javascript">
function showMonth(text) { //
dojo.xhrGet({
// The following URL must match that used to test the server.
url: "ajaxServlet?s="+text,
handleAs: "text",
// The LOAD function will be called on a successful response.
load: function(response, ioArgs) { //
dojo.byId("response").innerHTML = response + "Hereeee"; //
return response; //
},
// The ERROR function will be called in an error case.
error : function(response, ioArgs) { //
console.error("HTTP status code: ", ioArgs.xhr.status); //
dojo.byId("response").innerHTML = 'Loading the ressource from the server did not work'; //
return response; //
},
// Here you put the parameters to the server side program
// We send two hard-coded parameters
content : {
name : "lars",
url : "testing"
}
});
}
There is actually a property that you can use that's called preventCache
that will add a timestamp to each request (so cache is never used) if you set it on true
, you can read more about it at the reference guide . 实际上有一个属性可以使用名为
preventCache
的属性,它会为每个请求添加时间戳(因此永远不会使用缓存)如果将其设置为true
,您可以在参考指南中阅读更多相关信息。
In your case it would be: 在你的情况下,它将是:
function showMonth(text) { //
dojo.xhrGet({
// The following URL must match that used to test the server.
url: "ajaxServlet?s="+text,
handleAs: "text",
preventCache: true,
// The LOAD function will be called on a successful response.
load: function(response, ioArgs) { //
dojo.byId("response").innerHTML = response + "Hereeee"; //
return response; //
},
// The ERROR function will be called in an error case.
error : function(response, ioArgs) { //
console.error("HTTP status code: ", ioArgs.xhr.status); //
dojo.byId("response").innerHTML = 'Loading the ressource from the server did not work'; //
return response; //
},
// Here you put the parameters to the server side program
// We send two hard-coded parameters
content : {
name : "lars",
url : "testing"
}
});
}
Small note : The caching isn't Dojo specific, it's because GET
request should be used to request information, so that's why most browsers cache these requests to improve performance. 小注意 :缓存不是特定于Dojo的,因为
GET
请求应该用于请求信息,这就是大多数浏览器缓存这些请求以提高性能的原因。 All other type of requests ( POST
, PUT
, ...) are usually not cached. 所有其他类型的请求(
POST
, PUT
,...)通常不会被缓存。
I resolved it. 我解决了 I used 'preventCache: true' inside the function.
我在函数中使用了'preventCache:true'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.