-1
I’m studying JS, and I started to see about Asynchronmentalism, and I came to a class. I did as mentioned,but nothing appears in the browser network tab,nor returns error in the console,here is the code:
var minhaPromise = function(){
return new Promise(function(resolve, reject){
var xhr = new XMLHttpRequest()
xhr.open('GET', 'https://api.github.com/users/diego3g')
xhr.send(null)
xhr.onreadystatechange = function(){
if (xhr.readyState === 4){
if (xhr.status === 200){
resolve(JSON.parse(xhr.responseText))
} else{
reject('Erro na requisição')
}
}
}
})
}
minhaPromise()
.then(function(resolve){
console.log(resolve)
})
.catch(function(error){
console.warn(error)
})
Then I tried to use the bibliotexa Xios,:
axios.get('https://api.github.com/user/diego3g')
.then(function(response){
console.log(response)
})
.catch(function(error){
console.warn(error)
})
I didn’t get to test with Axios, but already in its first example, it worked normally, all data from the return of the github API were displayed on the console.
– Daniel Mendes