繁体   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