用jQuery播放声音通知

问题描述

我使用此功能来获取通知。我需要的是当我有新的通知来播放通知声音时。

function load_unseen_notification(view = '')
     {
      $.ajax({
       url:"fetch-notification.php",method:"POST",data:{view:view},dataType:"json",success:function(data)
       {
        $('.dropdown-menu').html(data.notification);
        if(data.unseen_notification > 0)
        {
         $('.count').html(data.unseen_notification);
         var audio = new Audio('http://localhost/ios_notification.mp3')
         audio.play()
     
        }
       }
      });
     }

解决方法

var audio = new Audio('http://localhost/ios_notification.mp3')

在此行中,您尝试调用Audio(url)的构造函数。您在http://localhost:80上运行服务器吗? 80http的默认端口。 +没有html5是不可能的,Audio构造函数的返回值为HTMLAudioElement

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...