-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
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
Labels
No labels