3

我有一个奇怪的 ajax 回调情况。

调用 A 工作正常(我可以在正确的位置看到服务器调用),并且正确触发了 done 回调。

调用 B 调用工作正常(我可以在正确的位置看到服务器调用),但随后 A 的 done 回调被触发!

这是代码:

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

和代码 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
    });
});

这里发生了什么???

4

1 回答 1

0

哦,伙计……我刚刚想通了。

所以我有:

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

复制html是我的错!

于 2013-05-01T15:30:07.263 回答