简体   繁体   English

播放 php ajax 的声音通知

[英]playing sound notification for php ajax

I am try to add a sound to it as soon as new data is added to the database but when i add to the script above, it plays the audio every 1 seconds我尝试在将新数据添加到数据库后立即为其添加声音,但是当我添加到上面的脚本时,它每 1 秒播放一次音频

var count_cases = -1;
setInterval(function(){    
    $.ajax({
        type : "POST",
        url : "cab_booking.php",
        success : function(response){
            if (count_cases != -1 && count_cases != response) alert('new record on i_case');
            count_cases = response;
        }
    });
},1000);

That is the expected behavior of setInterval() : it runs something repeatedly on the delay that you give it (in your case, 1000 or 1 second).这是setInterval()的预期行为:它会在您给它的延迟(在您的情况下为1000或 1 秒)重复运行某些东西。

I think you're intending to use setTimeout() instead of setInterval() .我认为您打算使用setTimeout()而不是setInterval()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM