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

后端 未结 3 508
一生所求
一生所求 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: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);
    

提交回复
热议问题