用于backbone.js ajax 请求的全局错误处理程序 [英] Global error handler for backbone.js ajax requests
本文介绍了用于backbone.js ajax 请求的全局错误处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法为backbone.js执行的ajax请求绑定一个错误处理程序?
Is there way to bind one error handler for ajax requests that performs by backbone.js?
我的情况:我可以随时收到 401(未授权),所以我需要显示登录弹出窗口.
My situation: I can get 401 (Unauthorized) at any time, so I need to show login popup.
推荐答案
为此直接使用 jQuery.
Use jQuery directly for this.
$(document).ajaxError(function (e, xhr, options) {
// do your stuff
});
例如,您可以在 rails 中对 CSRF 执行相同的操作(使用 ajaxSend).
You can do the same thing for CSRF in rails for exemple (using ajaxSend).
您可以在此处阅读更多信息:http://api.jquery.com/jQuery.ajax#advanced-options
You can read more here: http://api.jquery.com/jQuery.ajax#advanced-options
这篇关于用于backbone.js ajax 请求的全局错误处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文