我有以下代码对URL进行GET请求:
$('#searchButton').click(function() {
$('#inquiry').load('/portal/?f=searchBilling&pid=' + $('#query').val());
});
但是返回的结果并不总是被反映出来。例如,我对输出堆栈跟踪的响应进行了更改,但是当我单击搜索按钮时,堆栈跟踪没有出现。我查看了控制ajax响应的底层PHP代码,它有正确的代码,直接访问页面显示了正确的结果,但.load返回的输出是旧的。
如果我关闭浏览器并重新打开它,它会工作一次,然后开始返回陈旧的信息。我可以通过jQuery控制这一点,还是我需要有我的PHP脚本输出头来控制缓存?
/**
* Use this function as jQuery "load" to disable request caching in IE
* Example: $('selector').loadWithoutCache('url', function(){ //success function callback... });
**/
$.fn.loadWithoutCache = function (){
var elem = $(this);
var func = arguments[1];
$.ajax({
url: arguments[0],
cache: false,
dataType: "html",
success: function(data, textStatus, XMLHttpRequest) {
elem.html(data);
if(func != undefined){
func(data, textStatus, XMLHttpRequest);
}
}
});
return elem;
}
/**
* Use this function as jQuery "load" to disable request caching in IE
* Example: $('selector').loadWithoutCache('url', function(){ //success function callback... });
**/
$.fn.loadWithoutCache = function (){
var elem = $(this);
var func = arguments[1];
$.ajax({
url: arguments[0],
cache: false,
dataType: "html",
success: function(data, textStatus, XMLHttpRequest) {
elem.html(data);
if(func != undefined){
func(data, textStatus, XMLHttpRequest);
}
}
});
return elem;
}