0

I want to handle 404 error if script can't load some resouce after document is ready.
Here is code:

(function( $ ){

  $.fn.onair=function(){

    var tid = setInterval( function () {
    if ( document.readyState !== 'complete' ){
      return;
      alert("salam")
    }
      else if(document.readyState=='complete'){
          if (document.onerror){
        //ajax
         $.ajax({
  statusCode: {
    404: function() {
      alert("page not found");
    }
  }
});
         //ajax
         alert("s");
         clearInterval( tid );
         }
    }
}, 10 );

  }

})( jQuery )
2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Taywin
0

Try something similar to the script below... The status is whatever number you want to handle...

success: function(data, textStatus, XMLHttpRequest){
    console.log('Error: ' + textStatus);
},
error:function (xhr, ajaxOptions, thrownError){
    alert(xhr.status);
    alert(xhr.statusText);
    alert(xhr.responseText);
}
0

ok, thanks! If i want to do some function after the document loading completed and i want to do this after testing if document has error?

0

Yes, you could try to check what the response status from your ajax to see if you get an error back.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.