确保图像在 Ajax 调用中预加载
我注意到 jQuery Ajax 调用在回调之前不会预加载/加载目标页面的图像。所以基本上它只是加载 html,然后进行回调,回调后它开始加载图像。
所以我的问题是是否有一种方法可以确保目标页面图像也在附加函数之前加载/预加载。
示例代码:
$.ajax({
url: ''+nextHref+'',
success: function(data) {
var $response = $(data);
var oneval = $response.find('#ContainerWrapper').html();
// Then some kind of function that preloads the target images before it appends the ajax result. So basically the part below is where I don't know what o do.
$response.find('#ContainerWrapper img').examplepreloadfunction(function(){
$("#ContainerWrapper").append(oneval);
});
}
});
有任何答案、线索、想法或实验吗?
I have noticed that a jQuery Ajax call don't preload/load the images of the target page before it callbacks. So basically it just loads the html and then make the callback and after the callback it starts to load the image/images.
So my question is if there's a way to make sure that the target page images also gets loaded/preloaded before the append function.
Example Code:
$.ajax({
url: ''+nextHref+'',
success: function(data) {
var $response = $(data);
var oneval = $response.find('#ContainerWrapper').html();
// Then some kind of function that preloads the target images before it appends the ajax result. So basically the part below is where I don't know what o do.
$response.find('#ContainerWrapper img').examplepreloadfunction(function(){
$("#ContainerWrapper").append(oneval);
});
}
});
Any answers, clues, ideas or experiments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预加载图像:
或者:
在将从 AJAX 调用收到的 HTML 注入 DOM 之前,您可以对每个图像尝试此操作。
To preload an image:
or:
You could try this for each image before injecting the HTML you received from the AJAX call into the DOM.