I am trying to achieve the following effect: I have an HTML5 audio element using mediaelement.js with a playlist. I would like to activate a server query on every change of track (play, next etc.). I am using the HTML5 "playing" event, so far so good. I am sending an attribute of the current audio tag (src in my case) to a PHP script via AJAX and it is working ok, but I would like to put the HTML result from meta.php into a div in the page.
Here is my JS code:
$(document).ready(function() {
$("audio#mejs").on('playing',function(){
var source = $('#mejs').attr('src');
$.ajax({
url: "meta.php",
type: "GET",
data: "a=" + source,
dataType: 'html',
success: function(data) {
$('#nowPlaying').html(data);
alert(data);
}
});
});
});
The HTML elements are directly in the body tag:
<audio id="mejs" type="audio/mp3" width="600" height="64" src="http://"></audio>
<div id="#nowPlaying"></div>
I think I am missing something fundamental, I am quite new to JS/jQuery. Everything is working as intended except the .html() method does nothing.. Any help would be appreciated. Thank you!
<div>
id really the 11-character sequence#nowPlaying
, or is it the 10-character sequencenowPlaying
? – apsillers