nodejs开发中关于post提交数据
来源:互联网 发布:龙虎榜数据每天几点出 编辑:程序博客网 时间:2024/05/16 20:29
一、安装模块
- 1、
npm install body-parser --save
二、在app.js
中基本配置
1、引入刚刚安装的
body-parser
模块//引入关于post提交数据的const bodyParser = require("body-parser");
2、基本配置
//设置用来接收json格式的数据app.use(bodyParser.json());//设置接收任何数据类型app.use(bodyParser.urlencoded({extended:true}));
三、书写路由视图
router.post("/regpost2",(req,res)=>{ //如果是post提交数据就用req.body接收 console.log(req.body); db("insert into nodetest(name,age) values(?,?)",[req.body.username,req.body.age],(err,data)=>{ if (err){ res.json({ code:0, info:"注册失败" }); } console.log(data); if (data){ res.json({ code:1, info:"注册成功" }); } })});
四、总结
- 1、在
get
提交数据中node
后台接收前端传递过来的数据用req.query
- 2、在
post
提交数据中node
后台接收前端传递过来的数据用req.body
五、代码见demo
阅读全文
0 0
- nodejs开发中关于post提交数据
- 【解决方案】nodejs关于post提交表单的中文乱码问题
- nodejs的http.request使用post方式提交数据请求
- 在.NET 中模拟提交Post数据
- 在.NET 中模拟提交Post数据
- java中使用post提交数据
- delphi 中 使用 TIdHTTP 提交Post数据
- nodejs 获取post数据
- post提交中神秘消失的post数据
- Servlet中关于get提交和post提交的区别
- post提交数据
- c#post数据提交
- http post提交数据
- POST提交数据
- 使用POST提交数据
- android Post提交数据
- http post提交数据
- post提交数据
- nginx--静态访问图片资源(Banner)
- C C++面试题
- 系统解析开关电源中的MOS管--15大知识点!
- linux添加硬盘
- Android studio 导出jar包
- nodejs开发中关于post提交数据
- setters和getters方法
- linux命令中:wq和:wq!区别
- LCD MIPI DSI简析系列之二
- ES6常用语法
- banner轮播图
- [数论]线性求所有逆元的方法
- 慢查询日志详解
- 实现简单的万年历