How do I wait for an image to load after an ajax call using jquery?

后端 未结 3 501
一生所求
一生所求 2021-01-24 03:17

I have a Python script that is doing some manipulation on a JPEG image. I pass some parameters to this script and call it from my HTML page. The script returns an img src=\"newi

相关标签:
3条回答
  • 2021-01-24 03:20

    You can dynamically create a new image, bind something to its load event, and set the source:

    $('<img>').bind('load', function() {
        $(this).appendTo('body');
    }).attr('src', image_source);
    
    0 讨论(0)
  • 2021-01-24 03:25

    Image Loading

    Wait for ajaxRequest

    0 讨论(0)
  • 2021-01-24 03:35

    The other answers have mentioned how to do so with jQuery, but regardless of library that you use, ultimately you will be tying into the load event of the image.

    Without a library, you could do something like this:

    var el = document.getElementById('ImgLocation');
    
    var img = document.createElement('img');
    img.onload = function() {
        this.style.display = 'block';
    }
    img.src = '/path/to/image.jpg';
    img.style.display = 'none';
    
    el.appendChild(img);
    
    0 讨论(0)
提交回复
热议问题