开发者

jquery error function help

I'm not much of a javascript guy but I would like to implement error dialogs in this project I'm working on. I want to send a http header that the error function will catch and display the correct message. I've already tested the error function with an alert box and when I send a header 400, the error function is triggered.

Is it possible in JQuery or javascript to show different messages / dialogs based on the header code like 400 or 401? Based on that code then show the user the proper error message? I开发者_如何转开发 have about 4 or 5 messages that I need to show per error function

error:function(){
    // call my dialog here
}


The statusCode option is available in jQuery 1.5+ for jQuery.ajax:

A map of numeric HTTP codes and functions to be called when the response has the corresponding code. For example, the following will alert when the response status is a 404:

$.ajax({
  statusCode: {
    404: function() {
      alert('page not found');
    }
  }
});

If the request is successful, the status code functions take the same parameters as the success callback; if it results in an error, they take the same parameters as the error callback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜