简体   繁体   English

JQuery错误的ajax完成了回调

[英]JQuery wrong ajax done callback fired

I have a strange situation going on with ajax callbacks. 我有一个奇怪的情况正在进行ajax回调。

Call A works fine (I can see the server calls in the right place), and the done callback is fired correctly. 调用A工作正常(我可以在正确的位置看到服务器调用),并且正确触发完成的回调。

Call B call works fine (I can see the server calls in the right place), but then A's done callback is fired! 呼叫B呼叫工作正常(我可以在正确的位置看到服务器呼叫),但随后A的完成回调被触发!

Here's the code: A: 这是代码:A:

$(document).ready(function () {
    $('#beta_signup_form').submit(function() {
        var valuesToSubmit = $(this).serialize();
        $.ajax({
            url: $(this).attr('action'), //submits it to the given url of the form
            data: valuesToSubmit,
            dataType: "JSON", // you want a difference between normal and ajax-calls, and json is standard
            type: 'POST'
        }).done(function(json){
            console.log("in the beta signup form success function!!!!");
        })
        .fail(function () {
            console.log("--------> beta signup modal callback error");
        });
        return false; // prevents normal behaviour
    });
});

and code B: 和代码B:

$(document).ready(function () {
    $('#twitter_sign_up').submit(function() {
        var valuesToSubmit = $(this).serialize();
        $.ajax({
            url: $(this).attr('action'), //submits it to the given url of the form
            data: valuesToSubmit,
            dataType: "JSON", // you want a difference between normal and ajax-calls, and json is standard
            type: 'POST'
        }).done(function(json) {
             console.log("in success for modal B...");
        }).fail(function () {
            console.log("--------> modal B callback error");
        });
        return false; // prevents normal behaviour
    });
});

What's going on here??? 这里发生了什么???

OH man... I just figured it out. 哦,伙计......我刚想通了。

So I had: 所以我有:

<div id="twitter_sign_up">
  <form id="beta_signup_form" ...>
    ...
  </form>
</div>

My fault for copying html! 我复制HTML的错!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM