为什么ajax调用缓存表单数据
Why does ajax call cache form data?
下面的代码在第一次启动时运行良好,但如果我需要第二次发送(登录失败..),即使提交了新值,它也会重新发送原始表单数据。。。如何重置和重新加载数据。。
我已经尝试了很多东西,包括缓存:false(可能只适用于GET)和篡改url以避免浏览器缓存。。。到目前为止没有运气。请帮忙;-)
function procLogin() {
$.ajax({
type: 'POST',
url: 'http://www.lalala.com/lalala/auth.php?' + Math.random(),
crossDomain: true,
data: $("#loginForm").serialize(),
dataType: 'json',
async: false,
success: function(response) {
if (response.statusTFD == 'success') {
alert("Success");
} else if (response.statusTFD == 'error') {
alert("Authentication Invalid. Please try again!");
} else if (response.statusTFD.substring(0, 18) == 'Connection Failed:' || response.statusTFD.substring(0, 6) == 'Error:') {
alert(response.statusTFD);
} else {
alert("!¤#%¤!#" + response);
}
},
error: function(error) {
//alert(response.success);
alert('Could not connect to the database' + error);
}
});
return false;
}
以上是通过onsubmit调用的:
<form id="loginForm" method="POST" onsubmit="procLogin()">
在JS-中
$.ajaxSetup({
cache: false,
headers: {
'Cache-Control': 'no-cache'
}
});
在PHP 中
header('cache-control: no-cache');
同时使用两者可以避免缓存问题。
到目前为止,我提出的最好的解决方案是,如果用户/pw未通过身份验证,则执行location.reload();
。在这种情况下,重新加载登录页面,Ajax调用将接收提交的新值,而不是原始/缓存的值。。。不过,如果有人有意见的话,仍然有兴趣了解代码的错误。。?
谢谢你的帮助!
相关文章:
- 如何从pdftron webviewer获取表单数据
- JS验证ajax返回的html中的表单数据
- 在不同的文件中使用Javascript获取表单数据
- 使用Javascript读取Webstorage表单数据
- Uploadify-随机表单数据's已返回上载表单
- 如何在使用ajax提交的codeigniter中使用form_validation验证表单数据
- 在post-expressjs之后持久化表单数据
- 需要一个用于AJAX的Javascript库,其中包含多部分/表单数据
- jQuery发布并获取表单数据
- Ajax表单数据phpPOST不工作
- 如何将整个模型集附加到表单数据中,并在MVC中获得它
- 如何从javascript访问表单数据
- 如何从Angular Payments获取表单数据
- 通过javascript获取pdf文件的表单数据
- 有没有一种方法可以在jQuery.serialize()之前获取表单数据,或者与jQuery.sserialize(()
- 在 Angular2 中构建多部分/表单数据 POST 请求并验证输入类型文件
- 无法读取未定义的属性“用户名” - 通过电子邮件在 Node.js 中发送表单数据
- 使用 Ajax 获取表单数据
- 我无法从引导模式中清除表单数据
- 如何从 django 模板语言获取表单数据