How to get HTTP status code of

前端 未结 5 1639
逝去的感伤
逝去的感伤 2020-12-07 01:44

I have a page with a lot of images that are generated server-side depending on user actions. And when image loads successfully I\'m happy, but when there is an error on the

5条回答
  •  天涯浪人
    2020-12-07 01:49

    You have to add an eventListener on images :

    For example with jQuery :

    $('#your_image')
        .error(function(e) {
            //add your unhappy code here
    
            //unbind if needed
            $(this).unbind('error');
        })
        .load(function(e) {
            //add your happy code here
    
            //unbind if needed
            $(this).unbind('load');
        })
        ;
    

提交回复
热议问题