这是控制器中get_update方法的服务器端代码

  header('Content-Type: text/event-stream');
  header('Cache-Control: no-cache');
  header('Connection: keep-alive');
  ...
  $wait_time = gmdate('s', $query['max_wait']);
  echo "data: $wait_time\n\n";
  flush();


和javascript代码是(在jQuery中)

var source = new EventSource('get_update');
source.onmessage = function (event) {
    $('#total_logged').text(event.data);
};


这在Chrome甚至Forefox中都可以很好地工作。但是问题是,它在firefox中进行一次更新后停止工作(在重新加载工作一次,刷新完成后,工作两次,然后停止)。这里怎么了???

最佳答案

这是Firefox中的jQuery问题。 $(document).ready()此功能中的上述SSE代码在Firefox中无法连续工作。我在此函数之外找到了代码,现在可以正常工作了

07-28 11:03