37

I am using the following jQuery JSONP request to check the status of a resource by URL. When the resource is not available or the server is down, my ajaxFail() function updates the display.

function fetchServerStatus(service, host)
{
    var port = serverStatus[service].port;
    $.ajax({
        url: "http://" + host + ":" + port + "/admin/server/status",
        dataType: "jsonp",
        timeout: 1000,
        error: ajaxFail,
        fail: ajaxFail,
        success: ajaxDone,
        done: ajaxDone,
        complete: ajaxAlways,
        always: ajaxAlways
    });
}

The problem I'm having is that despite declaring handlers for fail and error, which do not log anything to the console, jQuery always logs the failed request in the console. If the resource is unavailable for a long time, this builds up a huge console log, eventually crashing the browser process (Chrome in my case).

Is there any way to stop it from doing this?

Will Hains
  • 996
  • 1
  • 12
  • 21
  • 1
    jQuery doesn't have log statements in it. Take a look at http://stackoverflow.com/questions/1215392/how-to-quickly-and-conveniently-disable-all-console-log-statements-in-my-code to prevent logging in general. – Pramod Aug 14 '12 at 09:14

2 Answers2

53

The logging entry in chrome's console is a behaviour of chrome when any HTTP request is handled, not a problem with jQuery or ajax(XMLHttpRequest), even an <img> or <link> tag could cause this issue.

Your only choice is to fix your server-side code not to trigger an error for ajax (eg. 404 not found or wrong content-type), so based on the content logged to console, maybe a better solution could be found, please provide accurate logging message in your console.

Prusprus
  • 7,987
  • 9
  • 42
  • 57
otakustay
  • 11,817
  • 4
  • 39
  • 43
  • 9
    This is a client side bug as error code is 4xx range, this sort of advice has 27 upvotes which I cannot believe! Client should errors better – simon-p-r May 26 '16 at 09:42
  • 2
    Unfortunately, a lot of REST web services return an `HTTP 400` error ("[malformed syntax](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1)") for **syntactically correct** requests. Good explanation at: http://stackoverflow.com/a/24610322 – Dem Pilafian Aug 04 '16 at 00:28
2

put this in the top of your page:

<script>

$(document).ready(function() {
jQuery.migrateMute = true;
})
</script>

its temporary - but worked for me. Beats having to scroll through 45 lines of nonsense to debug js errors.

Fstarocka Burns
  • 163
  • 1
  • 5
  • Maybe the reason jQuery creates those messages is that you have to change something in your code. They are in no way *nonsense*. Rather update your code! – Hidde Mar 24 '17 at 17:20
  • its got very little do with code - my code is fine. many chrome extensions do all kinds of weird things. I had 2 that I needed that were putting alot of nonsense in the console. Consider that b4 u downvote/assume i dont know that the console ERRORS are important - LOGGING (as the OP stated) is an entirely different issue. – Fstarocka Burns Apr 25 '17 at 05:49
  • This code can be useful when you are sure that everything works fine and want to push the project in product mode – Eniss Oct 18 '17 at 10:09
  • 1
    There are cases where you already have an error handler in an ajax call, and it helps to hide these errors. For example: if you want to check if a user has a specific image, and under ajax error function, you check if the default category has an image with the same name. In this case, it helps to hide the error, if you already know the ajax calls are working properly. It throws an error, but you're expecting that error, and already handled it. This answer can be helpful. Ideas can be out of the box, and do not always have to follow a typical standard. aspie's think out of the box :) – SwiftNinjaPro Sep 30 '19 at 12:28