Reputation: 2066
how can i play a sound if the content of a div is updated via ajax or $.ajax() and it not plays any sound if no content is updated....
i am using jquery with php and loading posts from database and want to play a sound if new posts found every 3-5 mintues...via $.ajax()
Upvotes: 1
Views: 3186
Reputation: 268324
You can setup jQuery's Sound Plugin. I'd auto-load the MP3, so there's very little wait between calling it, and hearing it. Then you would handle the response within your ajax call, and determine whether you'll play the sound or not.
$("#sound").sound({swf: url});
$("#sound").load(url);
$("#sound").play();
$("#sound").pause();
$("#sound").stop();
$("#sound").volume(0-100);
So running this every 4 minutes would look like:
$("#sound").load(url); // load our sound
setInterval(function(){
$.post("get-updates.php", {lastid:12}, function(response){
if (response.hasNewRecords)
$("#sound").play();
}, "JSON");
}, 240000);
Upvotes: 2
Reputation: 152206
Cross-browser solution is loading flash object that will play some sound.
Other way is using specific for every browser functions with JS (Firefox has it for 100%).
Third way - use browser's plugins: http://www.phon.ucl.ac.uk/home/mark/audio/play.htm.
About AJAX actions - call some onSuccess / success
event (do not know what lib you use).
Upvotes: 0