ajax的post方法相比get方法,在传参形式上很不一样, get把参数用'?'拼接在端口后,并且用'&'连接;而post则是需要在send参数里设置.

根据ajax实例xhr.setRequestHeader('content-type', )中第二个参数的不同,  send的参数也不相同.

最常用的有两种: application/x-www-form-encoded 和 application/json两种形式.

1
       const username = document.getElementById('username').value,
       password = document.getElementById("password").value;
     var xhr = new XMLHttpRequest();
xhr.open('POST','/test');
// xhr.setRequestHeader("content-type","application/x-www-form-urlencoded");
// xhr.send(`name=${username}&&password=${password}`);
xhr.setRequestHeader('content-type', 'application/json');
xhr.send(JSON.stringify({username, password}))

express本身只能用get方法,对用post方法的请求, 没法查看request的啥. 所以用第三方插件body-parser;

 const bodyParser = require('body-parser');
const app = express();
// var urlencodedParser = bodyParser.urlencoded({ extended: false });
// app.post('/test',urlencodedParser,(req,res)=>{
// console.log(req.body)
// }) var jsonParser = bodyParser.json();
app.post('/test',jsonParser,(req,res)=>{
console.log(req.body)
})

最新文章

  1. 函数图象(N=x+y*i)
  2. torch基本命令
  3. jstatd命令
  4. android手机打电话代码分析
  5. 程序不稳定是因为C++基础不扎实
  6. Python番外之 阻塞非阻塞,同步与异步,i/o模型
  7. android 关于多任务下载问题
  8. Java虚拟机参数设置(转)
  9. C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站
  10. Wireshark抓包介绍和TCP三次握手分析
  11. Java:从面试题“i++和++i哪个效率高?"开始学习java字节码
  12. (iOS)开发中收集的小方法
  13. PHP的 first day of 和 last day of
  14. java 打印空心菱形的两种实现
  15. Android 的 ListView 的CheckBox标题栏显示文本之后显示单选框
  16. WebService的一种简单应用方式入门
  17. spring in action 学习笔记八:用@Primary 或者@Qualifier消除@Autowired引起的歧义现象
  18. 大数据智能SOC解决方案
  19. 使用phpexcel导出到xls文件的时候出现乱码解决
  20. 数据备份及恢复(mongodump/mongorestore)

热门文章

  1. Node Buffer 利用 slice + indexOf 生成 split 方法
  2. js 获取滚动位置,滚动到指定位置,平滑滚动
  3. CF1242B. 0-1 MST
  4. System.currentTimeMillis和System.nanoTime()
  5. mysql LIKE通配符 语法
  6. Leetcode 16. 3Sum Closest(指针搜索)
  7. 3D Computer Grapihcs Using OpenGL - 06 Vertex and Fragment Shaders
  8. bootstrap动态调用select下拉框
  9. Linux Shell中捕获CTRL+C
  10. cookie格式化