app.js
var express = require('express')
, http = require('http');
var app = express();
app.set('port', process.env.PORT || 7002);
app.use(express.static(__dirname + '/public/images'));
app.post('/Details/',function(request,response,next){
app.use(express.bodyParser());
var keyName=request.query.Key;
console.log(keyName);
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
dev
收到的数据
.....显示为undefined
?var express = require('express')
, http = require('http');
var app = express();
app.set('port', process.env.PORT || 7002);
app.use(express.static(__dirname + '/public/images'));
app.use(express.bodyParser());
app.post('/Details/',function(request,response,next){
var keyName=request.query.Key;
console.log(keyName);
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
答案 0 :(得分:13)
而不是query
:
var keyName=request.query.Key;
console.log(keyName);
使用body
:
var keyName1=request.body.key;
console.log(keyName1);
代码:
var express = require('express')
, async = require('async')
, http = require('http');
var app = express();
app.set('port', process.env.PORT || 7002);
app.use(express.static(__dirname + '/public/images'));
app.use(express.bodyParser());
app.post('/Details/',function(request,response,next){
var keyName1=request.body.key;
console.log(keyName1);
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
答案 1 :(得分:9)
var express = require('express');
var app = express();
app.use(express.bodyParser());
app.post('/post/', function(req, res) {
// print to console
console.log(req.body);
// just call res.end(), or show as string on web
res.send(JSON.stringify(req.body, null, 4));
});
app.listen(7002);
答案 2 :(得分:7)
答案 3 :(得分:1)
您无法在中间件/路由处理程序中调用app.use(express.bodyParser());
:
bodyParser()
bodyParser()
,但它们将在app.router
之后并且永远不会正常工作答案 4 :(得分:0)
使用内置函数“ util”在快速js中打印任何类型的json数据
Combination #1: 25 Paisa x 0 + 50 Paisa x 10 = 5 Rs.
Combination #1: 25 Paisa x 2 + 50 Paisa x 9 = 5 Rs.
Combination #1: 25 Paisa x 4 + 50 Paisa x 8 = 5 Rs.
Combination #1: 25 Paisa x 6 + 50 Paisa x 7 = 5 Rs.
Combination #1: 25 Paisa x 8 + 50 Paisa x 6 = 5 Rs.
Combination #1: 25 Paisa x 10 + 50 Paisa x 5 = 5 Rs.
Combination #1: 25 Paisa x 12 + 50 Paisa x 4 = 5 Rs.
Combination #1: 25 Paisa x 14 + 50 Paisa x 3 = 5 Rs.
Combination #1: 25 Paisa x 16 + 50 Paisa x 2 = 5 Rs.
Combination #1: 25 Paisa x 18 + 50 Paisa x 1 = 5 Rs.
Combination #1: 25 Paisa x 20 + 50 Paisa x 0 = 5 Rs.