How to handle specific HTTP error for all AJAX calls?

前端 未结 1 1187
隐瞒了意图╮
隐瞒了意图╮ 2021-02-09 17:35

I have a web app, requesting and sending data via AJAX, and as a response, my server-side sends HTTP status codes, depending on the situation. so for example if a user tries to

相关标签:
1条回答
  • 2021-02-09 18:21

    You can use $.ajaxSetup() to register global error state handlers.

    Description: Set default values for future Ajax requests.

    Example:

    $.ajaxSetup({
        statusCode: {
            500: function(data) {
                alert('Some friendly error message goes here.');
            } 
        }   
    });
    
    0 讨论(0)
提交回复
热议问题