标签:end 对象 cal turn hang mis ISE http eject
1.axios 原理还是属于 XMLHttpRequest, 因此需要实现一个ajax。 
2.但还会需要一个promise对象来对结果进行处理。
3.ajax实现
var Ajax={
          get: function(url, fn) {
              // XMLHttpRequest对象用于在后台与服务器交换数据
              var xhr = new XMLHttpRequest();
              xhr.open(‘GET‘, url, true);
              xhr.onreadystatechange = function() {
                    // readyState == 4说明请求已完成
                    if (xhr.readyState == 4 && xhr.status == 200) {
                          // 从服务器获得数据
                          fn.call(this, xhr.responseText);
                    }
              };
                xhr.send();
          }
    }
axios实现
var Axios = {
          get: function(url) {
              return new Promise((resolve, reject) => {
                  var xhr = new XMLHttpRequest();
                  xhr.open(‘GET‘, url, true);
                  xhr.onreadystatechange = function() {
                        // readyState == 4说明请求已完成
                        if (xhr.readyState == 4 && xhr.status == 200) {
                              // 从服务器获得数据
                              resolve(xhr.responseText)
                        }
                    };
                    xhr.send();
               })
          },
    }
标签:end 对象 cal turn hang mis ISE http eject
原文地址:https://www.cnblogs.com/lishixiang-007/p/11273419.html