Как заставить функцию сработать? myFunction() в событии onended?
var load = (function () {
$.ajax({
url: "run.php",
type: "POST",
dataType: "JSON",
success: function send (audio1) {
if (!Array.isArray(audio1) || !audio1.length) {
div = document.getElementById('1');
div.innerHTML = "<div></div>";
console.log('2');
setTimeout(load,3000);
} else {
var track = audio1[0].track;
var t = audio1[0].time;
var UNIX_TIMESTAMP = Math.round(new Date().getTime() / 1000);
Date.prototype.getUnixTimestamp = function() {
return Math.round(this.getTime() / 1000);
};
var d = new Date();
var utime = d.getUnixTimestamp();
var time = ( utime - t );
console.log(time);
div = document.getElementById('1');
div.innerHTML = "<audio id='myAudio' controls onended='myFunction()'><source src='" + track + "'></audio>";
var audio = document.getElementById("myAudio");
audio.currentTime = time;
audio.autoplay = true;
}
}
});
});
load();
function myFunction() {
load();
}