简体   繁体   English

如何在ajax错误请求上捕获jquery异常?

[英]How to catch jquery exception on ajax bad request?

I am saving user model like this: 我正在保存这样的用户模型:

this.model.save(data,{
                    success: function(user) {
                        console.log(user);
                    },
                    error: function() {
                        console.log("error");
                    }

                });

REST api returns 400 (Bad request) when for example user name is not unique). 例如,用户名不唯一时,REST api返回400(错误请求)。 In console the "error" is displayed but BEFORE it there is jquery execption: 在控制台中显示“错误”,但在此之前有jQuery执行:

POST http://localhost/cms/users.json 400 (Bad Request)

how can I catch this exception so its not thrown to console? 我如何才能捕获此异常,以便不将其抛出控制台?

The exceptions are showed up on console as a feature of the browser (plug-in in case of Firebug). 例外作为浏览器的功能(在Firebug中为插件)显示在控制台上。 You cannot turn it off and it doesn't affect your code flow in any manner. 您不能将其关闭,也不会以任何方式影响您的代码流。 You should be ignoring it. 您应该忽略它。

Check this for another similar q 再次检查类似的q

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

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