PHP實作簡單的頁面語音播報功能(setInterval 循環播放)
JS代碼
$(function () {
var set = setInterval(function(){
$.post(root+“control/adIndex.php?cla=orderList&fun=getTime”, ‘’, function(data){
if (data.status){
var audio = new Audio(data.url); //擷取本地音頻檔案,ogg,mp3都可以
audio.play(); //執行播放操作
}
}, ‘json’);
}, 5000);
})
背景邏輯處理代碼
//定時任務
public function getTime()
{
//這裡插叙是否有新訂單,如果有就提示,沒有則忽略
$num = t h i s − > s q l Q u e r y A l l ( " s e l e c t ∗ f r o m o r d e r L i s t w h e r e o r d e r S t a t e = ′ 待 發 貨 ′ a n d p l a y = ′ ′ " ) ; i f ( ! e m p t y ( this->sqlQueryAll("select * from orderList where orderState='待發貨' and play=''"); if (!empty( this−>sqlQueryAll("select∗fromorderListwhereorderState=′待發貨′andplay=′′");if(!empty(num)){
$file=query(“systemFile”,“id=‘xu3rrjx17co8’”);
$json[‘status’]= 1;
j s o n [ ′ u r l ′ ] = r o o t . json['url']=root. json[′url′]=root.file[‘src’];
foreach ($num as KaTeX parse error: Expected '}', got 'EOF' at end of input: …"where"=>"id='{item[‘id’]}’"));
}
} else {
KaTeX parse error: Expected 'EOF', got '}' at position 28: …']= 0; }̲ return…json,320);
}