prevent未处理的jQuery的AJAX错误 [英] Prevent Unhandled jQuery AJAX Error

查看:122
本文介绍了prevent未处理的jQuery的AJAX错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何接收服务器数据或错误。有很多种方法。例如:

I know how to receive server data or error. There are many ways. For example:

$.ajax({
    type: "get",
    url: "/widgets/",
    success: function (data, text) {
        console.log('this is a data');
    },
    error: function (request, status, error) {
        console.log('this is an error');
    }
});

请看到这个图片:

我有我的错误的功能,我做什么,我需要在那里。 我怎样才能在第一线prevent错误。 我已经测试的4xx和5xx的错误,但没有任何区别。 我知道,最终用户不会看到此错误时,开发者控制台是隐藏的。

I have my error function and I do what I need there. How can I prevent error in the first line. I have tested 4xx and 5xx errors but no difference. I know that end user does not see this error when developer console is hidden.

我需要这个来设计的API。 我知道,我可以送200响应从服务器,以证明这是一个错误或一个成功的结果,一个额外的参数。

I need this to design an API. I know that I can send 200 responses from server with an additional argument that show that this is an error or a success result.

但是,如果我可以给4XX或5XX响应那么就没有必要额外的参数。 这种方式有一些额外的收获对我来说。例如,我可以成功,因此适用于我的客户端模型,无需担心额外的参数。

But if I can send 4xx or 5xx responses then there is no need to extra argument. This way has some additional gains for me. For example I can apply success result to my client side models without worry about additional args.

感谢您

推荐答案

AFAIK你不能使红一样的东西走开,返回错误状态 - codeS(4XX,5XX)时。他们所使用的浏览器,表示可能不会去的东西如预期。不过这些仅仅是装饰,因为4XX和5XX状态codeS是完全合法的,所以我没有看到你想要消灭他们一个理由。

AFAIK you cannot make the red thingies go away, when returning error status-codes (4xx, 5xx). They are used by the browser to indicate that something might have not gone as expected. Still these are mere decorations, since 4xx and 5xx status codes are perfectly valid, so I don't see a reason for you wanting to eliminate them.

就像你说的你自己,你的其他替代方法是发送的来自服务器200的响应与一个额外的参数,以证明这是一个错误或一个成功的结果的。

As you said yourself, your other alternative would be sending "200 responses from server with an additional argument that show that this is an error or a success result".

我一定会推荐使用4XX和5XX codeS,但(这就是他们设计的),并停止担心在开发者控制台(又名红一样的东西)浏览器的对决警告。

I certainly recommend using the 4xx and 5xx codes though (that's what they are designed for) and stop worrying about browser's heads-up warnings in developer console (aka red thingies).

另请参见<一个href="http://stackoverflow.com/questions/7035466/check-if-file-exists-but-$p$pvent-404-error-in-console-from-showing-up">this和的是获取其他各种资源时,请参考类似错误的问题(图像,文件等)。你看到的错误是同一性质的实际。

See also this and this questions that refer to similar errors when fetching other kinds of resources (images, files etc). The errors you see are actually of the same nature.

这篇关于prevent未处理的jQuery的AJAX错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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