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))