我正在尝试运行 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 调用?