刚开始看NODE.JS,有很多问题不明白,特向大家请教~
server监听8888端口,浏览器访问8888端口
server response 页面“index.html"
index.html中有一段:
<script type ="text/javascript" src="/test.js">
Chrome报错:
GET http://localhost:8888/test.js 404 (Not Found)
改为
<script type ="text/javascript" src="http://localhost:8888/test.js">
依然报错
GET http://localhost:8888/test.js 404 (Not Found)
只得改为用路由response的方法 ``<script type ="text/javascript" src="http://localhost:8888/gettest"` 同时后台requestHandler新增方法
function gettest(response, postData) {
console.log("Request handler 'upload' was called.");
fs.readFile(__dirname+'/test.js',
function(err,data){
response.writeHead(200,{"Content-Type": "application/x-javascript"});
response.write(data);
response.end();
}
);
}
代码运行正常了.
请问是我上面的代码有问题吗?