簡體   English   中英

如何從另一個Ajax調用的錯誤函數中運行Ajax調用?

[英]How can I run ajax call from within error function from another ajax call?

我正在嘗試運行ajax調用。 如果返回錯誤,我想捕獲responseText並將其發送到另一個具有php腳本的ajax調用,該腳本會將錯誤發送給我。

      $.ajax ({
            type: "POST",
            url: "includes/add_remove_favorite.php",
            dataType: "json",
            data: {
                "listingType" : listingType,
                "listingId" : listingId
            },
            success: function(data) {
                alert('The first ajax call worked');
            }, //end first ajax success
            error: function(data){ //If the listing doesn't update, display an error message
                var currentURL = window.location;       

                $.ajax ({
                    type: "POST",
                    url: "includes/error_email.php",
                    dataType: "json",
                    data: {
                        "url" : currentURL,
                        "errorMessage" : data.responseText
                    },
                    success: function(data) {
                        alert('The email sent successfully');
                    },

                    error: function(data){ //If the listing doesn't update, display an error message
                        alert('The email did not send');
                    }
                }); //end second ajax call

            } //end first ajax error
        }); //end first ajax call

我能夠從第一個ajax調用中獲取錯誤,所以我知道一個方法很好。 但是由於某種原因,第二個ajax調用中的郵件腳本不會發送,並且不會返回成功或錯誤消息,這告訴我ajax調用不起作用。

如何從另一個Ajax調用的錯誤函數中運行Ajax調用?

您需要使用window.location.href window.location是一個對象。

暫無
暫無

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

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