2013-04-25 57 views
0

我不明白爲什麼我不能在瀏覽器中獲得「我」的價值。 我得到這個ERREUR 101(淨值:: ERR_CONNECTION_RESET)如何將變量的值從Node.js發送到瀏覽器?

var http = require('http'); 
var i=0; 

http.createServer(function (req, res) { 
    i++; 
    res.writeHeader(200, {'Content-Type': 'text/plain'}); 
    res.write(i); 
    res.end(); 
}).listen(80, "127.0.0.1"); 

但是,如果它的工作:

res.write("i =" + i); 

謝謝

回答

2

答案很簡單:

由於i類型是號碼

龍答:

Socket.prototype.write定義請看:

Socket.prototype.write = function(chunk, encoding, cb) { 
    if (typeof chunk !== 'string' && !Buffer.isBuffer(chunk)) 
    throw new TypeError('invalid data'); 
    return stream.Duplex.prototype.write.apply(this, arguments); 
}; 
+0

謝謝Fardjad。 – Sam 2013-04-25 12:13:47

+0

@Christophe不用客氣。 – fardjad 2013-04-25 12:15:08

相關問題