H5接收服务器的推送(Server-Sent)
js代码:
<script>if(typeof(EventSource)!=="undefined"){var source=new EventSource("test.php");source.onmessage=function(event){ console.log(event.data)};}else{console.log('浏览器不支持Server-Sent')}</script>
php代码:
<?phpheader('Content-Type: text/event-stream');$arr = array( 'name'=>'lee');$data = json_encode($arr);echo "data: {$data}\n\n";
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。