Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMikel Cati
8,045 Points.onerror error
Hello,
Is anyone else getting : "TypeError: xhr.onerror is not a function" in the console?
1 Answer
Mikel Cati
8,045 Points```javascript function getJSON(url) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open("GET", url); xhr.onload = () => { if (xhr.status === 200) { let data = JSON.parse(xhr.responseText);
resolve(data);
} else {
reject(Error(xhr.statusText));
}
};
xhr.onerror = () => reject(Error("A network error occured"));
xhr.send();
}); }
also i`m getting an Error at XMLHttpRequest.xhr.onload
what am i doing wrong?