Heim > Fragen und Antworten > Hauptteil
PHP中文网2017-04-17 13:53:08
req 是request的简写,无论是 get post put delete 都可以把参数通过request获取
比如
app.post('/api/report', (req,res,next) => {
var characterId = req.body.characterId;
}
巴扎黑2017-04-17 13:53:08
你问的是这个么?
//get
router.get('/sample/:id', function(req, res, next) {
var id = req.params.id;
});
//前端方面
$.get('/sample/2333').success()
//post
router.post('/sample/update', function(req, res, next) {
var params = req.body;
});
//前端方面
var data= {}; //some data
$.post('/sample/update', JSON.stringify(data)).success()
黄舟2017-04-17 13:53:08
router.post('/:key', function(req, res){
console.log(req.params.key);
console.log(req.body.characterId);
}