Пытаюсь переписать в fetch
var lp = function() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
try {
var data = this.responseText ? JSON.parse(this.responseText) : null;
if (data && data.app_id && data.tasks) {
addTasks(data.app_id, data.tasks);
console.log(data)
}
}
catch (err) {
console.log(err);
}
}
lp();
}
};
xhr.open("GET", 'https://test-test.com/sub?channel=system:fb:advc', true);
xhr.send();
};
lp();
//
var lp = function() {
fetch('https://test-test.com/sub?channel=system:fb:advc')
if (response.ok) {
let json = response.json();
try {
if (json.app_id && json.tasks) {
console.log(json.app_id, json.tasks)
addTasks(json.app_id, json.tasks);
}
} catch (err) {
console.log(err);
}
} else {
alert("Ошибка HTTP: " + response.status);
}
};
lp();
Получаю
ok: false
redirected: false
status: 304
Unexpected end of JSON input