html页面添加语音提醒

发布时间:2022-05-24 16:35:19 阅读:1116次

   function longPolling() {
       $.ajax({
       type: "GET",
     url: "/index/index/music",
     timeout: 30000,  //超时时间30秒,30秒内没有完成请求,则取消请求然后error回调函数会被调用
     success: function (data) {  //返回的回调函数
         console.log(data.code)
         if (data.code == 1)//状态码为200,完全成功才响起提示音
         {
             playsound();
         }
         //也有状态码为204,也是success回调函数,但是textStatus==nocontent
         setTimeout(longPolling, 10000);     //再发起一个连接请求
         },
         error: function (XMLHttpRequest, textStatus, errorThrow) {
                   if (textStatus == "timeout")  //请求超时
                   {
                       setTimeout(longPolling, 10000);
                   } else      // 其他错误,如网络错误等
                   {
                       setTimeout(longPolling, 10000);
                   }
               }
           });
       }
   
       longPolling();
   
       //响起提示音
       function playsound() {
           var myAuto = document.getElementById('myaudio');
           // myAuto.src="/static/9725.wav";
           myAuto.src = "/static/index/1.mp3";
       }
   

image.png

上一篇:暂无
下一篇:暂无

站内搜索

会员信息

博主推荐

0.081969s