Friday, May 10, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  68] [ 1]  / answers: 1 / hits: 20176  / 8 Years ago, thu, november 10, 2016, 12:00:00

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


More From » c#

 Answers
10

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);
}
});


Chrome




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.


[#60106] Tuesday, November 8, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
larrycodys

Total Points: 394
Total Questions: 93
Total Answers: 78

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
;