
José Mauricio Chavarría González
Preguntastudent•hace 7 años
El código me da el error 0 😦 alguien sabe por qué?
function get(URL) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { const DONE = 4 const OK = 200 if (this.readyState === DONE) { if (this.status === OK) { //Todo OK resolve(JSON.parse(this.responseText)) }else { //Hubo un error reject(new Error(`Se produjo un error al realizar el request: ${this.status}`)) } } } xhr.open('GET', URL); xhr.send(null); }) } /*Funcion para tratar el error*/ function handleError(err){ console.log(`Request failed: ${err}`) } //Llamada al metodo let luke get('http://www.swapi.co/api/people/1/') .then((response) => { luke = response return get(luke.homeworld) }) .then((homeworld) => { luke.homeworld = homeworld console.log(`${luke.name} nació en ${luke.homeworld.name}`) }) .catch(err => handleError(err))

José Mauricio Chavarría González
student•hace 7 años
Muchas gracias!!

Diego Forero
Team Platzi•hace 7 años
cambia http por https, ya swapi solo responde https.