我有一个简单的注册页面,用于验证用户是否已被注册。
我使用 ajaxSetup 进行所有 ajax 调用,但由于某种原因,“成功”从未被调用。当我查看控制台(firebug)时,我可以看到一个成功的请求(代码 200 OK,结果是 true 或 false)。
这是我的代码:
$('#checkValidUsername').click(function() {
// some basic validation like not empty etc...
$.ajax({
type: "POST",
url: '/checkuser.php',
cache: false,
data: $("#form").serialize(),
dataType: 'json',
success: function(result) {
// do some actions
},
});
}
$.ajaxSetup({
beforeSend: function() {
// show loading dialog // works
},
complete: function(xhr, stat) {
// hide dialog // works
}
success: function(result,status,xhr) {
// not showing the alert
alert('success');
}
});
我的代码有什么问题吗? 谢谢
最佳答案
因为您已经在 $.ajax
调用中使用了 success
$('#checkValidUsername').click(function() {
// some basic validation like not empty etc...
$.ajax({
type: "POST",
url: '/checkuser.php',
cache: false,
data: $("#form").serialize(),
dataType: 'json'
/*
success: function(result) {
// do some actions
},
*/
});
}
$.ajaxSetup({
beforeSend: function() {
// show loading dialog // works
},
complete: function(xhr, stat) {
// hide dialog // works
}
success: function(result,status,xhr) {
// not showing the alert
alert('success');
}
});
$.ajax
中的所有内容都将覆盖 $.ajaxSetup
。
关于jquery - AjaxSetup从不执行成功函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7390454/