ajax异步提交的数据,使用
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