Global error handler for backbone.js ajax requests

前端 未结 4 2172
感动是毒
感动是毒 2020-12-23 13:02

Is there way to bind one error handler for ajax requests that performs by backbone.js?

My situation: I can get 401 (Unauthorized) at any time, so I need to show logi

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 13:44

    Use jQuery directly for this.

    $(document).ajaxError(function (e, xhr, options) {
      // do your stuff
    });
    

    You can do the same thing for CSRF in rails for exemple (using ajaxSend).

    You can read more here: http://api.jquery.com/jQuery.ajax#advanced-options

提交回复
热议问题