怎样获取从服务器返回的字符串数据

使用: xhr.responseText;

var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);

xhr.responseType = 'text';
xhr.onload = function () {
  if (xhr.readyState === 4 && xhr.status === 200) {
    console.log(xhr.responseText);
  }
};

xhr.send(null);

注意: xhr.responseType等于空字符或"text"时, 可以使用xhr.responseText获取

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