我有这个script
从中获取新邮件我database
播放通知声音用JavaScript
setInterval(function() {
$.ajax({
type: "GET",
url: "get_chat.php",
dataType: "html",
success: function (response) {
$(".msg_area").html(response);
}
});
}, 2000);
我尝试将声音一旦新数据添加到database
添加到它,但是当我加入在script
以上,它起着audio
每2 seconds
(我想这是因为它在setInterval
)
setInterval(function() {
$.ajax({
type: "GET",
url: "get_chat.php",
dataType: "html",
success: function (response) {
$(".msg_area").html(response);
var audio = new Audio('audio_file.mp3');
audio.play();
}
});
}, 2000);
所以请我问。只有当新数据添加到数据库时,我该如何播放声音?
是否每次都有“响应”来临? –