hh5*_*188 6 parameters get node.js express
我在客户端ajax一个GET请求:
$.ajax({
url: '/update',
type: 'get',
data: {
"key": key,
"value": value
},
success: function (data, err) {
}
})
Run Code Online (Sandbox Code Playgroud)
那么在节点方面,我想得到参数
var showParam = function (req, res) {
if (req.body) {
for (var key in req.body) {
console.log(key + ": " + req.body[key]);
}
res.send({status:'ok',message:'data received'});
} else {
console.log("nothing received");
res.send({status:'nok',message:'no Tweet received'});
}
}
app.get('/update', function(req, res){
showParam(req, res);
})
Run Code Online (Sandbox Code Playgroud)
shell显示正文是空的并且未定义.
但是当我更改get为post(在客户端和服务器端)时,一切正常,我可以正确获取参数.
我的代码有什么问题?我错过了什么吗?
| 归档时间: |
|
| 查看次数: |
5865 次 |
| 最近记录: |