netease-youdao / hex

heX
Other
1.52k stars 300 forks source link

nodejs http,Bug还是方法不对? #30

Closed molezzz closed 10 years ago

molezzz commented 10 years ago

代码如下:

<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <div>hello world</div>
    <script>
    var http = require('http');
    console.log(http);
    http.get("http://www.baidu.com", function(res) {
      console.log("Got response: " + res.statusCode);
      //console.log(res.body);
    }).on('error', function(e) {
      console.log("Got error: " + e.message);
    });
    </script>
  </body>
</html>

第一次运行,控制台可以打印出 Got response: 200 而后刷新页面,就开始报错了: Uncaught TypeError: undefined is not a function node.js:374 _tickCallback node.js:374

无论是Hex还是HeXium,都必须将程序关闭,再重新启动。

luyuan commented 10 years ago

查了一下 node.js 的 API,可以这么获得

var http = require('http'); console.log(http); http.get("http://www.baidu.com", function(res) { console.log("Got response: " + res.statusCode); //console.log(res.body); res.on('data', function(chunk) { console.log('BODY: ' + chunk); }); }).on('error', function(e) { console.log("Got error: " + e.message); });

Uncaught TypeError: undefined is not a function node.js:374 _tickCallback node.js:374 这个是目前刷新页面可能出现的问题,后期版本会修复。