0

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");
});

1 Answer 1

1

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.