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

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

问题描述

我有以下代码在 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());            
});

但返回的结果并不总是反映.例如,我对吐出堆栈跟踪的响应进行了更改,但是当我单击搜索按钮时,堆栈跟踪没有出现.我查看了控制 ajax 响应的底层 PHP 代码,它有正确的代码,直接访问页面显示正确的结果,但 .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?

推荐答案

如果你想在每个请求的基础上控制缓存,你必须使用更复杂的函数,比如 $.ajax().或者,如果您只想将其关闭,请将其放在脚本的顶部:

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天全站免登陆