【发布时间】:2020-03-16 14:52:30
【问题描述】:
我已经设置了一个应用程序,它在 Opera 和 Firefox 上运行良好,但在 Google Chrome 上它会缓存 AJAX 请求并提供过时的数据!
http://gapps.qk.com.au 是应用程序。在 Chrome 中运行时,它甚至不发送 AJAX 请求,但在另一个浏览器中尝试时,它总是发出 AJAX 请求并返回数据。
是否有任何方法(Apache/PHP/HTML/JS)来阻止 Chrome 执行此行为?
AJAX 调用:
function sendAjax(action,domain,idelement) {
//Create the variables
var xmlhttp,
tmp,
params = "action=" + action
+ "&domain=" + encodeURIComponent(domain)
xmlhttp = new XMLHttpRequest();
//Check to see if AJAX request has been sent
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
$('#'+idelement).html(xmlhttp.responseText);
}
};
xmlhttp.open("GET", "ajax.php?"+params, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//console.log(params);
xmlhttp.send(params);
}
sendAjax('gapps','example.com','gapps');
【问题讨论】:
-
PHP 脚本返回的标头是什么?确保它们不允许缓存,并返回适当的内容类型。
标签: javascript ajax google-chrome