AjaxSetup从来没有执行成功的功能从来没有、功能、AjaxSetup

2023-09-11 01:00:38 作者:小小世界里有个小小的俄

我有一个验证是否已被占用用户一个简单的注册页面。

I have a simple registration page that validates if a user is already taken.

我用ajaxSetup我所有Ajax调用,由于某种原因成功永远不会被调用。当我看到我的控制台(萤火虫),我可以看到一个成功的要求(code 200确定,我得到真或假的结果)。

I use ajaxSetup for all my ajax calls and for some reason the "success" is never called. When I look at my console (firebug) I can see a successfully request (code 200 OK and I get true or false as the result).

下面是我的code:

$('#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');
    }
});

什么是错我的code? 谢谢

What is wrong with my code? Thank you

推荐答案

由于您已经使用在你的 $。阿贾克斯成功 通话

because you are already using success in your $.ajax call

$('#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');
    }
});

一切都在 $。阿贾克斯将覆盖 $。ajaxSetup