Reputation: 325
In My page i am sending data to server side using 8 ajax call...
I don't want to handle ajax error for each and every ajax call......
Single ajax error handle all the ajax error in entire page....
is their any inheritance is possible for the entire page..
function SendConfirmationEmail(ShipmentID, ChannelOrderReference) {
var Url = '<%=Url.Action("SendShipmentEmail","Shipments") %>';
$.ajax({
cache: false,
type: "POST",
data: 'strOrderShipmentId=' + ShipmentID + '&channelOrderReference=' + ChannelOrderReference,
url: Url,
datatype: "HTML",
success: function (data) {
if (data == "1") {
SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'Email is successfully sent for Order#' + ChannelOrderReference + '');
}
if (data == "-2") {
SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'Email Template is not Choosen for this Store');
}
if (data == "-1") {
SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'Problem in Sending Email for Order#' + ChannelOrderReference + '');
}
if (data == "0") {
SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'Connection Failed to Send Email for Order# ' + ChannelOrderReference + '');
}
if (data == "-3") {
SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'ShipTo Email Address is Not Given for Order# ' + ChannelOrderReference + '');
}
// SucessErrorMessageDisplay('DivStatus', 'lblStatus', 'imgStatus', 0, 'Order# :' + ChannelOrderReference + ' is voided successfully');
},
error: function (xhr, ajaxOptions, thrownError) {
if (xhr.status == 403) {
window.location.href = '<%: Url.Action( "SessionExpire", "Home" ) %>';
}
}
});
}
Upvotes: 0
Views: 100
Reputation: 74410
$.ajaxError(function myErrorHandler(e, xhr, options, thrownError) {
alert("Ajax error!");
});
Should make the trick.
Upvotes: 2
Reputation: 12966
Hopefully I understand your question...
When you're calling JQuery's ajax
, you're passing in an object with several properties. One of these properties is error
. JQuery expects a function to be assigned to this property. You're supplying an anonymous function, but there's no reason why this can't instead be a reference to a function.
So you could define a function elsewhere in your script something like this:
function handleError(xhr, ajaxOptions, thrownError) {
if (xhr.status == 403) {
window.location.href = '<%: Url.Action( "SessionExpire", "Home" ) %>';
}
}
and then in your ajax calls, reference this:
$.ajax({
cache: false,
// etc...
error: handleError
});
Upvotes: 0