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 呼び出しからエラーを取得できるので、うまく機能することがわかります。しかし、何らかの理由で、2 番目の ajax 呼び出しのメール スクリプトが送信されず、成功またはエラー メッセージが返されず、ajax 呼び出しが機能していないことがわかります。
別の ajax 呼び出しのエラー関数内から ajax 呼び出しを実行するにはどうすればよいですか?