简体   繁体   English

Ajax只播放一次音频文件

[英]Ajax play audio file only once

I have a simple problem that I cant solve. 我有一个我无法解决的简单问题。 The logic should work, but for some reason its not working. 逻辑应该工作,但由于某种原因它不起作用。 Basically I have an ajax call which checks a status every 5 or so seconds.what I want to do is call an audio file only once! 基本上我有一个ajax调用,它每5秒左右检查一次状态。我想做的只是调用一次音频文件!

Unfortunately, this simple issue seems to be harder then I thought... 不幸的是,这个简单的问题似乎比我想的更难......

Can anyone tell me know I am going wrong? 谁能告诉我知道我错了?

Ajax function calls handleFencing... Ajax函数调用handleFencing ...

status = true;

function handleFencing(){
    if(status = true) {
        var snd = new Audio("sounds/beep.wav"); 
        snd.play();
        status = false;
     }
     else{}

}

Any help would be highly appreciated! 任何帮助将非常感谢!

Ryan 瑞安

You are assigning true to status not comparing 您将true指定为不比较的status

Should be 应该

if(status == true) {

instead of 代替

if(status = true) {

= is an assignment operator =是赋值运算符

== comparison operator ==比较运算符

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

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