Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从另一个ajax调用中运行error函数中的ajax调用?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 如何从另一个ajax调用中运行error函数中的ajax调用?

Javascript 如何从另一个ajax调用中运行error函数中的ajax调用?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在尝试运行一个ajax调用。如果返回错误,我想捕获responseText并将其发送给另一个ajax调用,该调用有一个php脚本,该脚本将把错误发送给我 $.ajax ({ type: "POST", url: "includes/add_remove_favorite.php", dataType: "json", data: { "listingTy

我正在尝试运行一个ajax调用。如果返回错误,我想捕获responseText并将其发送给另一个ajax调用,该调用有一个php脚本,该脚本将把错误发送给我

      $.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
<代码>窗口。位置是一个对象。

是的!这解决了问题。我不明白为什么我没有得到一个错误的回应,如果它是错误的类型,但我很高兴它现在的工作。谢谢你的帮助!