2014-08-29 18 views
0

與其他不同,對於我來說,Eve​​ntSource在Chrome和Firefox中都被觸發並正常工作。但是在Firefox中,當我在瀏覽器中收到消息時,我會收到一條錯誤消息。在Chrome中不會發生。Firefox中異常的EventSource錯誤

客戶端代碼:

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); 

服務器的NodeJS代碼:

***.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); 
    }); 
+1

嗯,*你得到了什麼*錯誤信息? – Bergi 2014-08-29 12:07:08

+0

您可以添加您正在使用的Node.JS服務器模塊嗎?我使用'http'並沒有遇到這個問題,但是我可能沒有足夠強調它? 'message'字符串有多大? – 2014-08-30 10:34:21

+0

@bergi,我收到的錯誤信息是空的,信息很小,100-200個字符,好奇的是,錯誤什麼也沒有做,只是出現。但將「傳輸編碼」更改爲「身份」固定了它。 – mido 2014-08-31 23:33:47

回答

1

找到了解決辦法嘍,

apparantly還有一個重要的頭,傳輸編碼 - 它應該或者是刪除,或保留爲身份,我想在Firefox中,它被視爲塊,默認情況下,這是導致問題。

一旦我在服務器中添加下面的行,錯誤飛走了。

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

我的源回答另一個problem

documentation