Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load data on-demand #33

Open
zhangzhike opened this issue Aug 9, 2018 · 0 comments
Open

load data on-demand #33

zhangzhike opened this issue Aug 9, 2018 · 0 comments

Comments

@zhangzhike
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant