ZhengXingchi / ZhengXingchi.github.io

Apache License 2.0
0 stars 0 forks source link

原生实现axios应该注意那些方面 #66

Open ZhengXingchi opened 4 years ago

ZhengXingchi commented 4 years ago

get请求

  var xml = null
    if (XMLHttpRequest) {
      xml = new XMLHttpRequest()
    } else {
      xml = new ActiveXObject('Microsoft.XMLHTTP')
    }
    //2.通过open与服务器建立连接    
    //open(method,url,async) ;
    //method包含 GET、POST、PUT方式。
    //第三个参数同步(false)或者异步(true)
    xml.open('Get', url.true)
    xml.send()
    xml.onreadystatechange = function () {
      if (xml.readystate === 4 && xml.status === 200) {
        // 请求成功
      } else {
        // 请求失败
      }
    }
ZhengXingchi commented 4 years ago

post请求

  var xml = null
    var data = {
      a: 1,
      b: 2
    }
    if (XMLHttpRequest) {
      xml = new XMLHttpRequest()
    } else {
      xml = new ActivexObject('Microsoft. XMLHTTP')
    }
    xml.open('POST', url, true)
    xml.send(data)
    xml.onreadystatechange = function () {
      if (xml.readystate === 4 && xml.status === 200) {
        // 请求成功
      } else {
        //请求失败
      }
    }