node.js - nodejs Restful风格怎么传参?
伊谢尔伦
伊谢尔伦 2017-04-17 13:51:08
0
3
612

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
洪涛

req is the abbreviation of request. Whether it is get post put delete or you can get the parameters through request

For example

app.post('/api/report', (req,res,next) => {
    var characterId = req.body.characterId;
    }
    
巴扎黑

Is this what you are asking?
//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()
黄舟
router.post('/:key', function(req, res){  
    console.log(req.params.key);
    console.log(req.body.characterId);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template