admin管理员组文章数量:1315017
I am using the following code to preload an mp3:
$.ajax({
url: "boom.mp3",
success: function() {
//done
}
});
Is there anyway I can have multiple elements preloaded (images and mp3 for example)?
e.g.
$.ajax({
url: "boom.mp3", "moo.jpg",
success: function() {
//done
}
});
Cheers!
I am using the following code to preload an mp3:
$.ajax({
url: "boom.mp3",
success: function() {
//done
}
});
Is there anyway I can have multiple elements preloaded (images and mp3 for example)?
e.g.
$.ajax({
url: "boom.mp3", "moo.jpg",
success: function() {
//done
}
});
Cheers!
Share Improve this question edited Apr 1, 2011 at 9:39 Barrie Reader asked Apr 1, 2011 at 9:32 Barrie ReaderBarrie Reader 10.7k11 gold badges77 silver badges141 bronze badges 2-
In the last code block, did you mean
url: ["boom.mp3", "moo.jpg"],
? – rxgx Commented Apr 1, 2011 at 9:51 - @rxgx: I think this is purely an example of what the OP is trying to achieve. – Neil Knight Commented Apr 1, 2011 at 12:42
3 Answers
Reset to default 8If you are using jQuery 1.5, there are two new ways to handle this: deferred and promises.
Creating Responsive Applications Using jQuery Deferred and Promises
function successFunc(){
console.log( “success!” );
}
function failureFunc(){
console.log( “failure!” );
}
$.when(
$.ajax( "/main.php" ),
$.ajax( "/modules.php" ),
$.ajax( "/lists.php" )
).then( successFunc, failureFunc );
To use this in your instance, for example, just replace the ajax
requests with load
.
An idea from me: Collect all filenames in an array and loop through the array. Save th received opjects in another array and use it for what you want.
Perhaps it will work if you define the object in the url parameter, seperated by colon.
<script>
$.ajax({
type:"GET",
url:'',
dataType:'json',
async:false,
beforeSend:function(data){ // Are not working with dataType:'jsonp'
$('#content').html('Loading...');
},
success:function(data){
$('#content').html(data.content);
}
});
</script>
Read beforeSend(jqXHR, settings)
本文标签: javascriptjQuery ajax() preloading multiple thingsStack Overflow
版权声明:本文标题:javascript - jQuery ajax() preloading multiple things - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741973921a2408006.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论