function GetData(){
var xhr=new XMLHttpRequest();
xhr.open("GET","http://localhost:1337/",true);
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
document.getElementById("res").innerHTML=xhr.responseText;
}
}
}
xhr.send(null);
}
var http = require("http");
var server=http.createServer(function(req,res){
if(req.url!=="/favicon.ico"){
res.writeHead(200,{"Content-Type":"text/plain","Access-Control-Allow-Origin":"http://localhost"});
res.write("你好啊!");
}
res.end();
});
server.listen(1337,"localhost",function(){
console.log("开始监听...");
});
刚开始学ajax 在我写好html页面后,我想把我写的页面加载到用nodejs创建的服务器,但是教程上说要把我的html放到服务器环境,我查找了各种资料,没有找到放到服务器的方法。在我的终端里输入node server.js之后我在网页上打开Localhost:1337/是一堆乱码,请问这要怎么解决啊?怎么把html放到服务器环境?