jQuery ajax()预加载多个东西 [英] jQuery ajax() preloading multiple things
本文介绍了jQuery ajax()预加载多个东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码预加载mp3:
I am using the following code to preload an mp3:
$.ajax({
url: "boom.mp3",
success: function() {
//done
}
});
无论如何我可以预装多个元素(例如图像和mp3)?
Is there anyway I can have multiple elements preloaded (images and mp3 for example)?
例如
$.ajax({
url: "boom.mp3", "moo.jpg",
success: function() {
//done
}
});
干杯!
推荐答案
如果您使用的是jQuery 1.5,则有两种新方法可以处理:延迟和承诺。
If you are using jQuery 1.5, there are two new ways to handle this: deferred and promises.
使用jQuery Deferred和Promises创建响应式应用程序
function successFunc(){
console.log( "success!" );
}
function failureFunc(){
console.log( "failure!" );
}
$.when(
$.ajax( "/main.php" ),
$.ajax( "/modules.php" ),
$.ajax( "/lists.php" )
).then( successFunc, failureFunc );
例如,要在您的实例中使用它,只需替换 ajax
请求加载
。
To use this in your instance, for example, just replace the ajax
requests with load
.
这篇关于jQuery ajax()预加载多个东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文