15

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

Christoph
  • 50,121
  • 21
  • 99
  • 128
user1750098
  • 151
  • 1
  • 1
  • 3
  • That is not an error that you can prevent other than making sure the image is always there. You have to make the request it will show up in the network requests/console. – epascarello Oct 16 '12 at 13:22
  • 1
    Its telling you a 404 error occurred because a 404 error *did* occur. The only way to avoid it would be to use a proxy script on the server – Alex K. Oct 16 '12 at 13:22
  • 1
    see this article: http://stackoverflow.com/questions/7035466/check-if-file-exists-but-prevent-404-error-in-console-from-showing-up – BishopZ Feb 15 '13 at 17:45

4 Answers4

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).

alexandernst
  • 14,352
  • 22
  • 97
  • 197
0

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.

jkmartindale
  • 523
  • 2
  • 9
  • 22
Moszeed
  • 1,037
  • 1
  • 10
  • 20
-2

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

Mari Selvan
  • 3,598
  • 3
  • 21
  • 36
-3

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

Amareswar
  • 2,048
  • 1
  • 20
  • 36