繁体   English   中英

创建一个全局Backbone.js错误视图

[英]Creating a Global Backbone.js error view

我想创建一个全局错误处理Backbone.js视图。 该视图应该能够处理所有服务器错误并通过在UI上显示适当的消息来作出反应。 谁能帮助您实现这一目标?

var NotificationView = Backbone.view.extend({

initialize: function () {
    //add your error dialogue window to body.

    $(document).ajaxComplete(function (event, xhr, settings) {

        try {
                //if you want to send error message from server side.
            if(xhr.status === 500) {
                result = $.parseJSON(xhr.responseText);
                this.show(result.message);
            }
            else if (xhr.status !== 200) { //sucess
                this.show("Something is not right !!!");
            }

            if(xhr.status === 200) {
                //success           
            }
        } catch(error) {}           
    });
},

show: function(message) {
   //show your dialogue with message.
},

hide: function() {
   //hide dialogue.
}
});

var notify = new NotificationView();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM