Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在启动函数之前等待ajax响应追加并加载内容_Ajax_Image_Resize_Load_Append - Fatal编程技术网

在启动函数之前等待ajax响应追加并加载内容

在启动函数之前等待ajax响应追加并加载内容,ajax,image,resize,load,append,Ajax,Image,Resize,Load,Append,嗨,我有一个项目,我从服务器上用ajax post获取帖子,我检测附加帖子中的图像,并使用函数根据它们的比率调整它们的大小 问题是,当我添加新帖子并尝试启动该函数时,它会将图像检测为大小(高度和宽度)0,因为图像尚未加载。我搜索过了,但没有找到任何答案,有一种方法可以检测ajax响应中的所有图像(其中包含其他元素)是否已使用.onload或其他替代方法加载 **Update** 我想: 检查ajax响应中的img元素长度:

嗨,我有一个项目,我从服务器上用ajax post获取帖子,我检测附加帖子中的图像,并使用函数根据它们的比率调整它们的大小

问题是,当我添加新帖子并尝试启动该函数时,它会将图像检测为大小(高度和宽度)0,因为图像尚未加载。我搜索过了,但没有找到任何答案,有一种方法可以检测ajax响应中的所有图像(其中包含其他元素)是否已使用.onload或其他替代方法加载

                                   **Update**
我想:

检查ajax响应中的img元素长度:

$("#yourelement").append(html);
var $dialog = $(html);
imglength = $dialog.find("img").length;
在每个加载的img上添加计数+,并检查其是否等于img长度:

n_images = 0;
$("#yourelement img").on('load', function(){ // check for every new image loaded in # 
n_images++;

if (n_images == imglength) {
//alert(imglength); // I used to verify if it works
yourfunction(); // will fire when all new images have been appended and loaded
}

});