I have this code (found from another StackOverflow question:
$(document).ready(function() {
$.ajax({
url: "soundfile.mp3",
success: function() {
$("#play_button").show();
}
});
});
This code works fine, but how can I amend it to handle multiple sound files?
Hmm. I think you have two options here: Either start multiple
$.ajax()requests at once by simply copy+pasting the block:Or run them successively by putting the next
$.ajax()request into thesuccesscallback of the previous one.I would tend to run the preloads successively because of the maximum connection limit on both the browser, and the server side. Opening a lot of simultaneous connections could slow down the loading of other important elements like images, JavaScript files and style sheets.