前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >express获取参数

express获取参数

作者头像
苦咖啡
发布2018-05-08 18:11:11
2.1K0
发布2018-05-08 18:11:11
举报
文章被收录于专栏:我的博客

ajax异步提交的数据,使用

代码语言:javascript
复制
     bodyParser = require('body-parser');
    //接收post
    app.use(bodyParser.urlencoded({extended: false}));
    app.use(bodyParser.json());
app.post("/get_new_message", function(req,res){//获取新消息
	res.writeHead(200, {'Content-type': 'text/plain'});
	console.log(req.param('uid'), req.param);
});
//express获取参数原型
function (name, defaultValue){
  var params = this.params || {};
  var body = this.body || {};
  var query = this.query || {};
  if (null != params[name] && params.hasOwnProperty(name)) return params[name];
  if (null != body[name]) return body[name];
  if (null != query[name]) return query[name];
  return defaultValue;

说明应该可以获取到get和post的所有参数 备注:body-parser非常重要,具体可以参考:https://github.com/expressjs/body-parser 具体原因你可以搜索 application/x-www-form-urlencoded

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014年9月20日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档