Load HTML5 Audio from Synchronous AJAX Call

In versions of iOS earlier than 4.2.1, this method of loading an audio file in the callback of a synchronous ajax call would work.

by quantum_leap123

HTML

<audio id="audio">
    <source src="https://wildathome.be/wp-content/uploads/2020/12/Vogels2.mp3" type="audio/mpeg" />
    <source src="http://dl.dropbox.com/u/1538714/article_resources/song.ogg" type="audio/ogg" />
</audio>

JavaScript

// run on page load
var audio = document.getElementById('audio');

jQuery.ajax({
    url: '/echo/json/',
    async: false,
    complete: function() {
        audio.play(); // audio will play in iOS before 4.2.1. Audio will not play in any iOS device 4.2.1 or later.
    }
});