$.ajax({
url: "captcheck.php",
type: "GET",
data: "code="+captcha.val(),
cache: false,
success: function (html) {
if (html==1) {
captcha.removeClass('validation-error',animateSpeed);
return true;
}
else {
captcha.addClass('validation-error',animateSpeed);
return false;
}
},
error: function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
现在这是一个非常简单的ajax函数,但它既没有成功被调用也没有错误,我检查了XHR与firebug上的响应及其完美,仍然没有成功也没有错误被调用。有人可以帮忙吗?
最佳答案
我无法在我这边测试你的代码,但我会给出我的两分钱:
添加“complete”回调函数,以帮助您确定代码中是否存在任何语法错误。来自 jQuery 文档:“‘Complete’是请求完成时(成功后)调用的函数并执行错误回调)”
使用简单的代码,如
alert('str')
和console.log('str')
内部回调函数用于调试。
顺便说一句,做addClass
和removeClass
支持多个参数吗?我在official document中找不到它.
关于jquery - $.ajax() 成功但错误未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773310/