我正在使用 php 进行长池化(工作正常)并将其输出 JSON 分配给 fullcalender 事件源。
我的js代码
var source = new EventSource(WEBROOT+'model/applongpooling.php?start=1476037800&end=1476642600');
source.addEventListener('message', function(e) {
console.log(e.data);
$('#calendar').fullCalendar( 'removeEvents');
$('#calendar').fullCalendar('addEventSource',e.data);// here i am getting error
}, false);
我的 php 池代码。
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function SetAppointment(){
//my logic which is working fine and giving me correct result
echo 'data: ' . json_encode($res) . "\n\n";//code to get output
echo PHP_EOL;
ob_flush();
flush();
}
do {
SetAppointment();
sleep(15);
// If we didn't use a while loop, the browser would essentially do polling
// every ~3seconds. Using the while, we keep the connection open and only make
// one request.
} while(true);
?>
在控制台中,我得到了正确的输出。
我收到错误,
在另一个 js 中,我还将事件源分配给 fullcalender,
eventSources: [
{
url:'model/appointments.php',
editable: true,
}
]
所以我的问题是我哪里错了,有什么建议吗?为什么我会收到这样的错误?