2014-04-25 2 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>"; 
    } 

} 

여기 내 자바 스크립트 : 나는 그것을하고 위의 코드에서 어떤 결과를 시도

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

변경하여 자바 스크립트하고이 링크를 사용하고 소리 알림을받을

enter code here 

jQuery를 (문서) .ready (함수() {

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` 

});