get和post的区别:
1.GET产生一个TCP数据包;POST产生两个TCP数据包。
  对于GET方式的请求,浏览器会把http header和data一并发送出去,服务器响应200(返回数据);
  而对于POST,浏览器先发送header,服务器响应100 continue,浏览器再发送data,服务器响应200 ok(返回数据)。
2.get请求数据有限制,post请求数据没有限制
3.请求参数在url中发送,post请求参数在http消息主体中发送

    //get
function get() {
//创建XMLHttpRequest
  let xhr = new XMLHttpRequest();
//监听响应
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 304)) {
      console.log(xhr.responseText);
    }
  };
  xhr.open("GET","your url",true);
  xhr.send();
} //post
function post () {
//请求参数、url、创建XMLHttpRequest
  let data = 'name=tom&age=18',
    url = 'your url',
    xhr = new XMLHttpRequest();   xhr.open('post', url);
//设置header
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xhr.send(data);
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && ( xhr.status === 200 || xhr.status === 304 )){
      console.log(xhr.responseText);
    }
  }
}

参考:1.https://blog.csdn.net/u012391923/article/details/53197387?utm_source=blogxgwz3
   2.http://www.runoob.com/tags/html-httpmethods.html

最新文章

  1. Ubuntu14.04无法在var/www内新建文档
  2. Python 写Windows Service服务程序
  3. 关于C# byte[]与struct的转换
  4. bzoj 2561: 最小生成树
  5. bzoj 1500: [NOI2005]维修数列 splay
  6. mysql_windows_安装版添加到服务开机自启动
  7. CSS文字大小单位PX、EM、PT
  8. Windows下MongoDB常用命令
  9. vue 倒计时组件
  10. Hadoop源码分析(1):HDFS读写过程解析
  11. socket编程: TypeError: must be bytes or buffer, not str
  12. windows下的拷贝利器robocopy
  13. 30行Python代码实现人脸检测
  14. mybatis generator生成文件大小写问题
  15. Linux 字符设备驱动开发基础(二)—— 编写简单 PWM 设备驱动【转】
  16. 手机开发-IOS
  17. ios的单元測试OCUnit以及更新了之后的XCTestCase
  18. 2013-8-6 ubuntu基本操作
  19. java基本语法二
  20. 算法笔记(c++)--关于01背包的滚动数组

热门文章

  1. linux 常用shell脚本语句
  2. HDU2457 DNA repair —— AC自动机 + DP
  3. 【LeetCode】最大子序和
  4. html5--1.14 特殊符号的使用
  5. Java_正则_00_资源贴
  6. Java微信公众平台开发_05_微信网页授权
  7. java面试题04
  8. Java命名规范(简略)
  9. BZOJ 1567: [JSOI2008]Blue Mary的战役地图
  10. 图形化升级单机oracle 11.2.0.1 到 11.2.0.4