= =ajax发送的数据在node端怎么获取 在request里面找了半天没找到的说 求救
http.createServer(function(request, response) {
var postData = "";
var pathname = url.parse(request.url).pathname;
request.setEncoding(“utf8”);
request.addListener("data", function(postDataChunk) {
postData += postDataChunk;
});
request.addListener('end’, function(){
info = querystring.parse(postData);
//console.log(info);
});
}).listen(8888);
$.ajax({ type: 'POST’, data: { username: 1231, password: 42141 }, url: 'http://localhost:8080/test’, dataType: 'json’, success: function (data) { console.log(data) } });
我用jquery的ajax发送发现进不去end事件 而且data事件只进入一次postDataChunk居然是… = =这是怎么回事啊
function test(response, request) { var postData = ""; request.addListener("data", function(postDataChunk) { postData += postDataChunk; }); request.addListener('end’, function(){ info = querystring.parse(postData); console.log(info); response.writeHead(200); response.end(info); }); } 服务端改成这样的 不知道哪里错了