How to determine error code on broken images using mootools

I need a script that can determine the reason the image is not loading based on the provided HTTP status code.

I am aware of the onError event on images and objects, but it does not pass an error code. So if an image has a broken source or a timeout has occurred, it is treated the same.

I would like to have a script that can determine the error code and act accordingly. For instance:

  • 404 - replace the image with a predefined
  • 403 - Admin Notification Using Callback Function
  • 504 - try rebooting
  • and etc.

I did some google searches, but besides the onError event, I came to an end.

Any ideas?

+3
1

, , - xhr , Asset.image :

new Asset.image('foo.jpg', {
    onload: function() {
        someel.adopt(this);
    },
    onerror: function() {
        new Request({
            url: this.get('src'),
            onComplete: function() {
                console.log(this.status); // 404
            }
        }).get();
    }

});

http://jsfiddle.net/dimitar/2hwej/

, 2 . , xhr, , base64 - .

+1

All Articles