对于Backbone.js的Ajax请求全局错误处理程序 [英] Global error handler for backbone.js ajax requests

查看:184
本文介绍了对于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
});

您可以做CSRF同样的事情在轨的为例(使用ajaxSend)。

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

您可以在这里阅读更多:<一href=\"http://api.jquery.com/jQuery.ajax#advanced-options\">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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆