nodejs 如何返回数据,ajax 可以接收到
JScript code
require('http').createServer(function (req, res1) {
res1.writeHead(200, {'Content-Type': 'text/plain'});
var request = require('./request');
request.request('login', {
account: require('./params').account,
password: require('./params').password
}, function(res){
res1.write( res.body );
});
}).listen(8080, "127.0.0.1");
res.body 是一段json数据,我想在本地通过ajax请求http://127.0.0.1:8080这个地址get到res.body里面的数据
请问下大家 我这个server端应该怎么改? 求救啊
大侠帮忙
------解决方案--------------------
用socket.io吧
------解决方案--------------------
http://www.veryhuo.com/a/view/39821.html
------解决方案--------------------
require('http').createServer(function (req, res1) {
//res1.writeHead(200, {'Content-Type': 'text/plain'});
var request = require('./request');
request.request('login',
{
account: require('./params').account,
password: require('./params').password
}, function(res){
res1.writeHead(200, {'Content-Type': 'text/plain'});
res1.write( res.body );
res1.end();
});
}).listen(8080, "127.0.0.1");