CNode

= =ajax发送的数据在node端怎么获取

Wwbb123yu发布于13 年前最后回复13 年前10 回复6937 浏览0 收藏

= =ajax发送的数据在node端怎么获取 在request里面找了半天没找到的说 求救

查看回复

回复 (10)

W
wbb123yu#1·13 年前
引用 hexie如果用express,如果是Post 就 req.query, get就 req.body

= =不用express就没办法了吗 不会吧

H
hexie#2·13 年前

那你贴出代码

H
hexie#3·13 年前

如果用express,如果是Post 就 req.query, get就 req.body

W
wbb123yu#4·13 年前
引用 hexie那你贴出代码

啊 我都不知道怎么取到ajax值啊 后面都没法写 怎么贴代码啊

D
dengqiao#5·13 年前
引用 hexie如果用express,如果是Post 就 req.query, get就 req.body

@wbb123yu 请使用express,用http还是要看看这个的

H
hades#6·13 年前

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);

W
wbb123yu#7·13 年前
引用 hadeshttp.createServer(function(request, response) { var postData = ""; var pathname = url.parse(requ...

$.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居然是... = =这是怎么回事啊

W
wbb123yu#8·13 年前
引用 hadeshttp.createServer(function(request, response) { var postData = ""; var pathname = url.parse(requ...

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); }); } 服务端改成这样的 不知道哪里错了

W
wbb123yu#9·13 年前
引用 hexie如果用express,如果是Post 就 req.query, get就 req.body

@dengqiao = =是吗 ... 不是很想用express 而且他也是框架吧 他能做到的原版node也可以吧

W
wbb123yu#10·13 年前
引用 hadeshttp.createServer(function(request, response) { var postData = ""; var pathname = url.parse(requ...

0.0 啊啊 发现了 是调试模式估计断点的时候end事件结束了 然后就卡在那边了 搞定了 谢谢

参与回复
登录后即可参与回复。登录