Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php HTML5服务器发送事件:空响应_Php_Javascript_Codeigniter_Server Sent Events - Fatal编程技术网

Php HTML5服务器发送事件:空响应

Php HTML5服务器发送事件:空响应,php,javascript,codeigniter,server-sent-events,Php,Javascript,Codeigniter,Server Sent Events,我正在使用PHP(CodeIgniter)编写一个web服务。 我试着学习HTML5中服务器发送事件的一些基本教程 然而,我无法运行任何一个 正如预期的那样,我收到了正确的标题(每3秒一次),但我没有收到任何数据。 可能是WAMP配置或CodeIgniter问题吗 控制器方法的代码: public function sse() { header('Content-Type: text/event-stream'); header('Cache-Control:

我正在使用PHP(CodeIgniter)编写一个web服务。 我试着学习HTML5中服务器发送事件的一些基本教程

然而,我无法运行任何一个
正如预期的那样,我收到了正确的标题(每3秒一次),但我没有收到任何数据。
可能是WAMP配置或CodeIgniter问题吗


控制器方法的代码:

public function sse() {
        header('Content-Type: text/event-stream');
        header('Cache-Control: no-cache');
        $time = date('r');
        echo "data: The server time is: {$time}\n\n";
        flush();
    }
视图的代码(部分):


我也遇到了同样的问题,我通过在标题和响应/结果中用双引号替换单引号解决了这个问题

   header("Content-type: text/event-stream");
   header("Connection: Keep-alive");
   header("Cache-Control: no-cache");
   echo "retry:1000\n";
   $result = "data:".json_encode($result)."\n\n"; 

根据您显示的标题,您有一个响应。你确定里面没有数据吗?在Chrome'Firebug'中,我得到了“此请求没有可用的响应数据。”并且onmessage函数从未实际调用过。我是否错过了什么,事实上我可能正在接收数据吗?@mechu,我有完全相同的问题
onmessage
未被激发,并且数据始终为空,即使当我手动输入文件时,数据也不是空的。我不知道发生了什么。。。(附言:特兹·波尔斯基)
Request URL:http://localhost/index.php/play/sse
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/event-stream
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie: ...
   header("Content-type: text/event-stream");
   header("Connection: Keep-alive");
   header("Cache-Control: no-cache");
   echo "retry:1000\n";
   $result = "data:".json_encode($result)."\n\n";