Задать вопрос
@ubbe_lodbroke

Не могу понять почему в .catch прилетает undefined?

const applyProducts = (url) => {
            return new Promise((resolve, reject) => {
                let xhr = new XMLHttpRequest();
                open('GET', url);
                xhr.onload = () => {
                    if (xhr.status === 200){
                        let json = JSON.parse(xhr.response);
                        resolve(json)
                    } else{
                        reject(xhr.statusText)
                    }
                };
                xhr.onerror = (error) => reject(error);
                xhr.send()
            })
        };

        applyProducts(`p1.json`)
            .then((json) => console.log(json))
            .catch((status) => console.error(status))
  • Вопрос задан
  • 79 просмотров
Подписаться 1 Средний Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы