How to get HTTP status code of

前端 未结 5 1632
逝去的感伤
逝去的感伤 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:56

    You may combine the couple technics to get img.status:

    
    
    function error(img) {
       var r = makeXMLHttpRequestAgain(img.src);
       if (r.status === 500) img.src = '/e500.img';
       if (r.status === 503) img.src = '/e503.img';
    }
    

提交回复
热议问题