2014-04-25 36 views
0

我是新的程序员,特别是codeigniter。当我收到数据并将其保存在数据库中时,我有一份工作要对我的项目做出合理的通知。使用codeigniter和javascript声音通知

我有下面的代码我控制器上:

foreach($data["arr_data_lastalert"] as $data_last_alert) 
{ 
    if($data_last_alert["alertTypeId"]==1){ 
     echo "<script>soundSOS();</script>"; 
    }else if($data_last_alert["alertTypeId"]==2){ 
     echo "<script>soundOverspeed();</script>"; 
    }else if($data_last_alert["alertTypeId"]==3){ 
     echo "<script>soundGeofence();</script>"; 
    } 

} 

,并在这里我的javascript:

function soundSOS(){ 
    $('<audio id="chatAudio"><source  src="https://raw.githubusercontent.com/RavensKrag/WireFu/master/data/beep-08.wav" type="audio/wav"></audio>').appendTo('lastAlert'); 
    $('#chatAudio').play(); 

}

我已经尝试过了,从上面的代码没有结果。我该怎么做呢?有没有其他方法可以使其运行?请帮帮我。谢谢。

+0

您可以使用HTML 5 Web Sound API? =) –

回答

0

改变你的JavaScript和使用这个链接进行,你会得到声音通知

enter code here 

jQuery的(文件)。就绪(函数(){

jQuery(".navigation a").click(function(e){ 

    var nextPage = $(this).attr('href');//save reference to the clicked url 

    jQuery("<audio>").attr({//create the audio object 

     "hidden":true, 

     "autostart":true, 

     "loop":false, 

     "src":"http:/yourpath/html/horse.mp3" 

    }).bind("ended",function(){//when audio finishes playing update the page to new url 

     document.location.href = nextPage 

    }).appendTo("#dummy");//add the audio to the DOM 

    jQuery("audio")[0].play(); 

    e.preventDefault();//preve`enter code here`nt the page from following the link right away 

});`enter code here` 

});