AjaxSetup从来没有执行成功的功能 [英] AjaxSetup never execute the success function

查看:288
本文介绍了AjaxSetup从来没有执行成功的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于AjaxSetup从来没有执行成功的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆