0
I’m making an AJAX request using the Github API from Axios and wanted to know how I do to, while uploading the information, it give a console.log('carregando');
and create a component written "loading", and after that it deletes the loading messages.
This is my current code:
axios.get('https:api.github.com/users/marceloh13')
.then(function(response){
console.log(response);
console.log(response.data.avatar_url)
})
.catch(function(error){
console.log(error);
});
however later I wanted to change this console.log to a <H1> written "loading" and after it loads the <H1> some, that way n would work.
– Marcelo Henrique Dos Reis
On the contrary. Just replace the first
console.log
forajaxFeedback.hidden = false;
and theconsole.log
of the latterthen
forajaxFeedback.hidden = true
. In this case it would be necessary thatajaxFeedback
is already assigned.– fernandosavio
I added a Jsfiddle with a working example to give you an idea.
– fernandosavio
Fernando, I don’t understand how I create a <H1> component like this.
– Marcelo Henrique Dos Reis
If you want to create one
<h1>
each time a request is started would have to usedocument.createElement('h1')
and then add to the DOM withappendChild
orinsertBefore
. But this is not at all performatic, so I just show and hide the element. But the point is not this, with the code shown already gives to have notion of where to put your codes to give feedback to user.– fernandosavio