输入“密码”时出现 jQuery ajax 错误进入密码字段
这是一个非常奇怪的错误,我希望有人以前遇到过它。
我正在使用 jQuery 的 $.ajax 方法从登录脚本发布数据。每次我刷新登录页面并第一次在密码字段中输入“密码”一词时,都会触发 $.ajax 的 error() 方法,即 ajax 无法与服务器通信。如果我在不刷新页面的情况下重试,它可以顺利地与服务器通信。
总而言之,在密码输入字段中输入“password”一词会导致 $.ajax 失败。我发誓这不是我编造的!
var action = $('#myForm').attr('action');
var email = $('#myForm input[name=email]').val();
var password = $('#myForm input[name=password]').val();
$.ajax({
url: action,
type: 'POST',
data: {
email: email,
password: password
},
dataType: 'json',
timeout: 20000,
cache: false,
error: function(xhr,status,error){
alert('Cannot communicate');
},
success: function(data){
alert('OK');
}
});
This is a very strange bug and I hope someone has encountered it before.
I'm using jQuery's $.ajax method to post data from a login script. Each time I refresh the login page and enter the word "password" into the password field for the first time, $.ajax's error() method is triggered i.e. ajax fails to communicate with the server. If I then try again without refreshing the page, it manages to communicate with the server without a hitch.
So to summarise, entering the word "password" into a password input field causes $.ajax to fail. I swear I'm not making this up!
var action = $('#myForm').attr('action');
var email = $('#myForm input[name=email]').val();
var password = $('#myForm input[name=password]').val();
$.ajax({
url: action,
type: 'POST',
data: {
email: email,
password: password
},
dataType: 'json',
timeout: 20000,
cache: false,
error: function(xhr,status,error){
alert('Cannot communicate');
},
success: function(data){
alert('OK');
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉浪费了时间,但我刚刚发现了这个问题,而且它不是 jQuery bug。我返回了一个格式错误的 json 对象,该对象触发了 error() 方法。有时候,连续编码 16 个小时后,你会只见树木不见森林。
Sorry for the waste of time, but I've just found the problem and it wasn't a jQuery bug. I was returning a malformed json object which triggered the error() method. Sometimes you can't see the woods for the trees after coding for 16 hours straight.