【发布时间】:2017-02-25 13:31:04
【问题描述】:
我有这个script 来接收来自我的database 的新消息
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);
所以请教一下。如何仅在将新数据添加到数据库时播放声音?
【问题讨论】:
-
每次
response来了吗?
标签: javascript jquery html audio