Skip to content

load data on-demand #8

@zhangzhike

Description

@zhangzhike

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions