We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我们在编写node应用时候,获取前端表单传来的数据这是很常见的需求,我们现在以express为例, 创建服务器、但是我们后端要接受前端传来的数据,这是body-parser就派上了作用.
前端
const axios = require('axios') // create server axios({ method: 'POST', url: 'http://localhost:8090/save', data: { username: '执念', password: '1243', email: 'zhinian@126.com' } }).then(result => { console.log('请求发送成功',result) })
后端
const express = require('express') const bodyParser = require('body-parser') const app = express() // body-parser app.use(bodyParser.json()) app.use(bodyParser.urlencoded({extended: false})) app.get('/', function (req, res, next) { res.send('express-body-parser 使用') }) // save app.post('/save', function(req, res, next) { let user = req.body; console.log(user) }) app.listen(8090, function () { console.log('started 8090') })
演示效果
到这里就是express body-parser的简单演示, 要想了解更多请查看官网
The text was updated successfully, but these errors were encountered:
No branches or pull requests
前端
后端
演示效果
到这里就是express body-parser的简单演示, 要想了解更多请查看官网
The text was updated successfully, but these errors were encountered: