Reputation: 6762
I am trying to show any type of Ajax request response errors through a common dialog just like a common error page. Do we have any option to catch error descriptions from different Ajax calls in different pages and show it with common Ajax error event?
$(document).ajaxError(function(){
alert("error description is :" +"error desc error from xyz page");
});
Upvotes: 0
Views: 244
Reputation: 2399
You can make utility wrapper function for ajax error call like
window.ajaxError =function(errorCode, desc,page){
//error code if needed
alert("error description is :" +desc+ "from xyz page"+page);
};
and in ajax call you can use it.
var menuId = $( "ul.nav" ).first().attr( "id" );
var request = $.ajax({
url: "script.php",
type: "POST",
data: { id : menuId },
dataType: "html"
});
request.done(function( msg ) {
$( "#log" ).html( msg );
});
request.fail(function( jqXHR, textStatus ) {
window.ajaxError(jqXHR,textStatus,document.URL);
});
Upvotes: 1