Asynchronously load images with jQuery

前端 未结 10 2402
日久生厌
日久生厌 2020-11-22 06:52

I want to load external images on my page asynchronously using jQuery and I have tried the following:

$.ajax({ 
   url: \"http://somedomain.         


        
10条回答
  •  半阙折子戏
    2020-11-22 07:21

    use .load to load your image. to test if you get an error ( let's say 404 ) you can do the following:

    $("#img_id").error(function(){
      //$(this).hide();
      //alert("img not loaded");
      //some action you whant here
    });
    

    careful - .error() event will not trigger when the src attribute is empty for an image.

提交回复
热议问题