Eliminate 404 url error in console?

折月煮酒 提交于 2019-12-29 07:31:23

问题


I try to eleminate an 404 error occuring because the source (src) is missing..

var $chart = $("<img />")
    .addClass("trend-pic")
    .error(function(){
        console.log("error loading..")
    });
try{
    $chart.attr("src", jobs[counter].url + "test/trend")
}catch(err){
    $chart.attr("src", "");
}    

if tried many stuff to catch the error i.e. putting an .error(function(){}) at the end. use the $chart.load() - method to check if the images gets loaded? Non of those helped?

GET {myURLString} 404 (Not Found)

Browser: Safari


回答1:


You can't really delete those 404 errors from the console. The best you can do is make some ajax calls and see the return code, but then you'll be limited to request only to your own domain.

EDIT--

Oh, and yes, those errors will keep showing in the "Requests" tab! They just won't appear in the "Console" tab (in Chrome).




回答2:


I think there is no way to eliminate the error from your console, except using the right url. In your code with the try {} catch() the error is thrown and $chart.attr will be called again with an empty string.

What you can do is add a check like this before you set the .attr()

if (jobs[counter].url !== void 0 && 
    jobs[counter].url.length !== 0) {

       $chart.attr("src", jobs[counter].url + "test/trend")
}

so you can remove the try{} catch()

Hope it helps.




回答3:


Just the answer is No.Because this is the only way Server send "there is a Error".

Refer this one.

Prevent 404 Error in console




回答4:


404 is not an error. It is the way server says it does not have the source referred by the client.



来源:https://stackoverflow.com/questions/12915582/eliminate-404-url-error-in-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!