EventSource

  1. 作者QQ:67065435 QQ群:821635552

  2. 本站内容全部为作者原创,转载请注明出处!

  3. 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();
    
  4. 对应js代码

     var source = new EventSource("http://localhost/index.php");
     source.onmessage = function(event)
     {
         console.log(event.data);
     };
    
Copyright © 豆包嘿嘿~ 2012-∞ 冀ICP备17033181号 all right reserved,powered by Gitbook修订: 2020-08-19 14:05:41

results matching ""

    No results matching ""