在jQuery.ajax中清除缓存 [英] Clear Cache in jQuery.ajax
问题描述
Hi Firends
我正在使用$ .ajax并面临缓存问题,但是我已经标记了
Hi Firends
I am working with $.ajax and facing an cache issue, however I have mark the
cache:false
在我的
$.ajax
请求中。
服务器端代码工作正常,它返回应有的结果。我尝试调试代码,发现虽然结果很好,但是ajax成功方法中的
request.
The server side code is working fine it returns the results as it should be. I tried to debug the code and found though the result is coming fine but
data.d
返回/显示第一个执行的结果。
例如:在我的第一次搜索中,服务器返回1条记录,在第二次搜索中返回70条记录。我成功地能够在
in ajax success method is returning / displaying the first executed result.
For example: In my 1st search for and server returns me 1 record, in 2nd search it return 70 records. I am successfully able to show the records in the
jqGrid
中显示记录,但在内部循环记录以搜索
, but internally when I loop the records to search on
item
变量只包含1条记录而不是70条。
以下是我的代码:
variable in my code below it contains only 1 record instead of 70.
Below is my code:
$.ajaxSetup({
// Disable caching of AJAX responses
cache: false
});
$("#tblSearch").jqGrid("clearGridData", true).trigger("reloadGrid");
var abc = Math.random();
$.ajax({
url: "abc.aspx/somemethod",
data: JSON.stringify({ isActive: SIsActive, clientName: sName}),
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "POST",
cache: false,
success: function (Data) {
var item = undefined;
item = $.parseJSON(Data.d);
var items = undefined;
for (var i = 0; i < item.length; i++) {
var asu = item[i];
if (ClientID == asu.ClientID) {
// some code here
break;
}
}
item.length
不等于到了70.
在解决了这个问题之后,我找到了浏览器IE,默认情况下会在同一个请求中保留缓存。所以我尝试通过将随机值传递给url来更改请求。
is not equals to 70.
After goggling this issue I found the browser IE, by default preserve the cache on the same request. So I tried to change the request by passing a random value to the url.
var abc = Math.random();
但它对我不起作用。
如果您有任何猜测或成功,请指导我。
谢谢
But it didn't work for me.
Any guess or success from your side please guide me.
Thanks
推荐答案
.ajax并面临缓存问题,但是我已经标记了
.ajax and facing an cache issue, however I have mark the
cache:false
in我的
.ajax
请求。
服务器端代码工作正常,它返回结果应该是。我尝试调试代码,发现虽然结果很好,但是ajax成功方法中的
request.
The server side code is working fine it returns the results as it should be. I tried to debug the code and found though the result is coming fine but
data.d
返回/显示第一个执行的结果。
例如:在我的第一次搜索中,服务器返回1条记录,在第二次搜索中返回70条记录。我成功地能够在
in ajax success method is returning / displaying the first executed result.
For example: In my 1st search for and server returns me 1 record, in 2nd search it return 70 records. I am successfully able to show the records in the
jqGrid
中显示记录,但在内部循环记录以搜索
, but internally when I loop the records to search on
item
变量只包含1条记录而不是70条。
以下是我的代码:
variable in my code below it contains only 1 record instead of 70.
Below is my code:
.ajaxSetup({
// 禁用AJAX响应的缓存
cache: false
});
.ajaxSetup({ // Disable caching of AJAX responses cache: false });
这篇关于在jQuery.ajax中清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!