簡體   English   中英

JQuery錯誤的ajax完成了回調

[英]JQuery wrong ajax done callback fired

我有一個奇怪的情況正在進行ajax回調。

調用A工作正常(我可以在正確的位置看到服務器調用),並且正確觸發完成的回調。

呼叫B呼叫工作正常(我可以在正確的位置看到服務器呼叫),但隨后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
    });
});

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

這里發生了什么???

哦,伙計......我剛想通了。

所以我有:

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

我復制HTML的錯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM