Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

javascript - How can I stop jQuery.ajax() from logging failures to the console?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...