停止jQuery的.load被缓存的响应 [英] Stop jQuery .load response from being cached

查看:111
本文介绍了停止jQuery的.load被缓存的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code使得对URL的GET请求:

I have the following code making a GET request on a URL:

$('#searchButton').click(function() {
    $('#inquiry').load('/portal/?f=searchBilling&pid=' + $('#query').val());            
});

但是,返回的结果并不总是反映。比如,我做了回应这一变化吐出一个堆栈跟踪,但是当我点击搜索按钮的堆栈跟踪都没有出现。我看了看下面的PHP code控制Ajax响应,并有正确的code和访问页面直接显示出正确的结果,而是由.load返回的输出是老了。

But the returned result is not always reflected. For example, I made a change in the response that spit out a stack trace but the stack trace did not appear when I clicked on the search button. I looked at the underlying PHP code that controls the ajax response and it had the correct code and visiting the page directly showed the correct result but the output returned by .load was old.

如果我关闭浏览器,然后重新打开它的作品,然后开始返回陈旧的信息。我可以用jQuery的控制这还是我需要让我的PHP脚本的输出头控制缓存?

If I close the browser and reopen it it works once and then starts to return the stale information. Can I control this by jQuery or do I need to have my PHP script output headers to control caching?

推荐答案

您必须使用更复杂的功能,如 $。阿贾克斯()如果你想控制缓存在每个请求的基础。或者,如果你只是想将其关闭的一切,把这个在脚本的顶部:

You have to use a more complex function like $.ajax() if you want to control caching on a per-request basis. Or, if you just want to turn it off for everything, put this at the top of your script:

$.ajaxSetup ({
    // Disable caching of AJAX responses
    cache: false
});

这篇关于停止jQuery的.load被缓存的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆