怎样获取从服务器返回的数据体

使用: xhr.response 属性, 可获得response body 内的数据, 注意, 这些数据类型不一样, 比如字符串 / 对象 / 二进制文件 等. 

var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function () {
  if (xhr.readyState === 4) {
    handler(xhr.response);
  }
}

注意: 

1. 如果返回的是xml或html, xhr.response会自动解析成网页文档, 而xhr.responseText 不会;

2. 如果xhr.responseType类型非空或为Text, 且xhr.readyState等于3, 则xhr.response 里面是存在从服务器返回的部分数据的;

原文地址:https://www.cnblogs.com/aisowe/p/11555232.html