Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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
Javascript Firefox中的异常EventSource错误_Javascript_Html_Firefox_Server Sent Events - Fatal编程技术网

Javascript Firefox中的异常EventSource错误

Javascript Firefox中的异常EventSource错误,javascript,html,firefox,server-sent-events,Javascript,Html,Firefox,Server Sent Events,与其他人不同的是,对我来说,EventSource在Chrome和Firefox中都能被触发并正常工作。但在Firefox中,每当我在浏览器中收到消息时,我都会收到一条错误消息。不发生在铬 客户端代码: var source = new EventSource('***'); source.addEventListener('message', function(event) { ... }, false); source.addEventListener('ping', functi

与其他人不同的是,对我来说,EventSource在Chrome和Firefox中都能被触发并正常工作。但在Firefox中,每当我在浏览器中收到消息时,我都会收到一条错误消息。不发生在铬

客户端代码:

var source = new EventSource('***');
source.addEventListener('message', function(event) { 
    ...
}, false);
source.addEventListener('ping', function(e) {
    ...
}, false);

source.addEventListener('error', function(e) {
    ... // now this part gets executed in firefox, whenever i recieve a msg
}, false);
服务器,节点代码:

    ***.on('fin',function(message){
        delete ***;
        res.header('Content-Type', 'text/event-stream');
        res.write('data: '+JSON.stringify(message)+'\n\n');
        res.end();
    });
    ***.on('busError',function(){
        delete ***;
        res.send(500);
    });

我自己找到了解决办法

显然,有一个重要的标题,传输编码——它要么被删除,要么作为标识保留,我猜在firefox中,它默认被视为块,这就是问题的根源

一旦我在服务器中添加了下面的行,错误就消失了

res.header('Transfer-Encoding','identity')

我的消息来源是另一个的答案


那么,您会收到什么错误消息?您可以添加您正在使用的Node.JS服务器模块吗?我使用了“http”,但没有解决这个问题,但也许我只是强调得不够?你的
消息
字符串有多大?@bergi,我收到的错误消息是空的,消息很小,100-200个字符,奇怪的是,错误什么都没有,只是出现了。但将“传输编码”更改为“标识”解决了这一问题。