OrgChart-Webcomponents icon indicating copy to clipboard operation
OrgChart-Webcomponents copied to clipboard

load data on-demand

Open zhangzhike opened this issue 7 years ago • 0 comments

hello, Web Components,I Just debugged on-demand loading logic and found something wrong. The code is as follows: _getJSON(url) { return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest();

  function handler() {
    if (this.readyState !== 4) {
      return;
    }
    if (this.status === 200) {
      resolve(JSON.parse(this.response));
    } else {
      reject(new Error(this.statusText));
    }
  }
  xhr.open('GET', url);
  xhr.onreadystatechange = handler;
  xhr.responseType = 'json';
  // xhr.setRequestHeader('Accept', 'application/json');
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send();
});

} Now that xhr. setRequestHeader ('Content - Type', application / json') is set, the return data does not have to be processed by JSON. parse (this. response). Otherwise, what do you think?

zhangzhike avatar Aug 08 '18 09:08 zhangzhike