是否有可能赶上net :: ERR_BLOCKED_BY_CLIENT? [英] Is it possible to catch net::ERR_BLOCKED_BY_CLIENT?

查看:438
本文介绍了是否有可能赶上net :: ERR_BLOCKED_BY_CLIENT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我们的网站上,我们进行了各种搜索,其中一些可以正常工作并返回适当的结果。其中一些返回javascript错误:


当我在
上搜索时,无法加载资源:net :: ERR_BLOCKED_BY_CLIENT我已经发现问题是我在谷歌浏览器中运行AdBlocker,而AdBlocker导致了这个问题。

现在我知道我可以关闭AdBlocker,这很好,我有,但是有没有办法让我在javascript中捕获这个错误,并向用户报告为什么他们没有得到任何搜索结果?



理想情况下,我在类似于ac#try / catch之类的东西。



编辑:
确定,所以经过一些挖掘并指出正确的方向从下面的评论我认为我已经推断了这个问题,希望这将有助于其他人。



在阅读<一个href =https://stackoverflow.com/questions/32748315/getjson-fail-not-firing>这个它看起来像我试图完成不能使用jQuery的版本我们目前运行(1.10.x),所以我想解决方案是使用新版本的jQuery(2.x),看看我是否可以捕捉到错误

解决方案

不幸的是,你不能专门捕获错误信息,但你可以自己发现错误:

  $。 ajax({
url:'http://openx.net',
dataType:'json',
成功:函数(数据){
console.log(成功:,data);
},
error:function(data){
consol e.log(错误:,数据);
}
});


很显然,这个例子并不是在请求JSON,而是您可以看到它失败并调用错误处理程序。


Chrome会触发这些错误,例如,像Adblock这样的插件(如您所述)会取消请求。

So on our site we have various searches some of which work fine and return the appropriate results. A few of them however return the javascript error:

Failed to load resource: net::ERR_BLOCKED_BY_CLIENT when I search on my machine.

I have found out that issue is that I am running AdBlocker in Google Chrome and it is AdBlocker that is causing the problem. Now I know I could just turn AdBlocker off which is fine and I have, but is there a way for me to catch this error in javascript and report to the user why they are not getting any search results?

Ideally I am after something similar to a c# try/catch.

EDIT: OK, so after some digging around and being pointed in the right direction from the comments below I think I have deduced the issue, hopefully this will help others.

After having read this it looks like what I am trying to accomplish cannot be done using the version of jQuery we are currently running (1.10.x) so I guess the solution is to use a new version of jQuery (2.x) and see if I can catch the error

解决方案

Unfortunately you cannot catch that error message specifically, but you can catch the error itself:

$.ajax({
  url: 'http://openx.net',
  dataType: 'json',
  success: function( data ) {
    console.log( "Success:", data);
  },
  error: function( data ) {
    console.log( "Error:", data);
  }
});

Obviously the example isn't requesting JSON, but you can see that it fails and calls the error handler.

These errors are fired by Chrome when, for instance, a plugin like Adblock (as you mentioned) cancels a request.

这篇关于是否有可能赶上net :: ERR_BLOCKED_BY_CLIENT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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