我如何等待图像Ajax调用使用jQuery后装入? [英] How do I wait for an image to load after an ajax call using jquery?

查看:119
本文介绍了我如何等待图像Ajax调用使用jQuery后装入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python脚本,做一些操作上的JPEG图像。我传递一些参数,这个脚本,并从我的HTML页面调用它。该脚本返回一个IMG SRC =newimage.jpg标签。

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="newimage.jpg tag.

我知道如何等待剧本的答复,但我不知道如何告诉当图像完全加载(当它是,我想要显示它)。图像加载缓慢,因此用户是看到这个加载过程中我现在得到的是。相反,我希望有一个味精告诉用户,而图像加载等待,才把我想要显示的图像。

I know how to wait for the reply from the script but I don't know how to tell when the image is fully loaded (when it is, I want to display it). What I get now is the image loading slowly so the user is seeing this "loading" process. Instead, I want to have a msg telling the user to wait while the image is loading, only then I want to display the image.

推荐答案

您可以动态地创建一个新的形象,结合东西,它的加载事件,并设置源:

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);

这篇关于我如何等待图像Ajax调用使用jQuery后装入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆