如何在 $.getJSON() 中传递 `Cache: false`

How to pass `Cache: false` in $.getJSON()

我在 IE 10 中有一个 ajax 调用缓存问题。解决方案是在 ajax 调用中传递 cache: false。我面临着这个问题。我怎样才能在其中传递 Cache: false

$.getJSON(url , function(data){ //some code here }
$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

或:

$.ajax({
    type: "GET",
    cache: false,
    url: "yourURL",
    //other settings
    success: function(data) {
      //do something with data
    }
});

这样试试:

$(document).ready(function() {
  $.ajaxSetup({ cache: false });
});

即,您需要调用 jQuery.ajaxSetup() 方法并将值 false 传递给缓存 属性,这将导致 jQuery 在 ajax 调用时禁用缓存。

正如 Jitesh 回答 here 你可以试试这个:

$.ajaxSetup({ cache: true});
$.getJSON("/MyQueryUrl",function(data,item) {
     // do stuff with callback data
     $.ajaxSetup({ cache: false});
   });

您不能将任何配置参数传递给 $.getJSON。正如 documentation 所述,这是一个 shorthand 函数:

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
})

因此您可以只使用该代码然后设置 cache: false 或使用 $.ajaxSetup 全局设置。

JSONObject  jsobj = new JSONObject();
JSONArray  jsobjs = new JSONArray();

我遇到了类似的问题。我尝试了以上所有建议,但问题没有得到解决。然后我发现在我的 servlet class 中我在 class 级别声明了两个对象。我将这些声明移到了 doPost() 方法中。 问题得到解决。 !!!