Javascript 使用DOJO时会缓存AJAX响应

Javascript 使用DOJO时会缓存AJAX响应,javascript,jquery,ajax,caching,dojo,Javascript,Jquery,Ajax,Caching,Dojo,我正在使用下面的DOJO功能进行AJAX调用。但不幸的是,特定请求的响应被缓存。即使我更改了servlet端的代码,它也不会反映在我之前尝试过的情况中。我猜响应被缓存了。我正在使用Tomcat服务器。 有人能帮忙吗 <script type="text/javascript"> function showMonth(text) { // dojo.xhrGet({ // The following URL must match that used to test th

我正在使用下面的DOJO功能进行AJAX调用。但不幸的是,特定请求的响应被缓存。即使我更改了servlet端的代码,它也不会反映在我之前尝试过的情况中。我猜响应被缓存了。我正在使用Tomcat服务器。 有人能帮忙吗

<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"
                }
            });
}

函数showMonth(文本){//
dojo.xhrGet({
//以下URL必须与用于测试服务器的URL匹配。
url:“ajaxServlet?s=“+文本,
handleAs:“文本”,
//成功响应时将调用LOAD函数。
加载:函数(响应,ioArgs){//
dojo.byId(“response”).innerHTML=response+“hereee”;//
返回响应;//
},
//错误情况下将调用ERROR函数。
错误:函数(响应,ioArgs){//
错误(“HTTP状态代码:”,ioArgs.xhr.status)//
dojo.byId(“response”).innerHTML=“从服务器加载ressource不起作用”;//
返回响应;//
},
//在这里,您将参数放入服务器端程序
//我们发送两个硬编码参数
内容:{
姓名:“拉尔斯”,
url:“测试”
}
});
}

实际上,您可以使用一个名为
preventCache
的属性,该属性将为每个请求添加一个时间戳(因此从不使用缓存)。如果将其设置为
true
,您可以在

在您的情况下,它将是:

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:缓存不是特定于Dojo的,这是因为
GET
request应该用于请求信息,所以大多数浏览器都会缓存这些请求以提高性能。所有其他类型的请求(
POST
PUT
,…)通常不会被缓存。

我解决了它。我在函数中使用了“preventCache:true”。

谢谢Dimitri。那一个奏效了。谢谢你提供的额外信息。