EventSource

  1. php代码

     # index.php
     <?php
     header('Cache-Control: no-cache');
     header('Content-Type: text/event-stream');
     $time = date('Y-m-d H:i:s');
     echo "retry:1000\ndata: {$time}\n\n";
     flush();
    
  2. 对应js代码

     var source=new EventSource("http://localhost/index.php");
     source.onmessage=function(event)
     {
         console.log(event.data);
     };
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-01-11 16:52:19

results matching ""

    No results matching ""