4
I have a function in jquery that has a while that writes data to the database, and after this while it prints on console that the data was saved, the function is like this:
function gravaDados(){
var qtde_linhas = 6 //ele pega a quantidade de linhas da tabela a ser salvo
var x = 1;
while( x <= qtde_linhas ) {
...//dados AJAX
... console.log('Dados gravados'); //salva os registros
x++;
}
console.log('dados salvos com sucesso '+x);
}
In the console appears that were saved the data and the current position of x is 7 ie he saved the 6 lines in the database, but my doubt is the following because the console.log
from within the while
is last printed?
As seen in the image it records the data but prints the console in reverse, this is due to the delay of writing the data in the database, or if I insert another function in place of the last console I may have problems of the data not being finished and execute the other function? For now it’s working, but I have this question, or is there a way for him to check if the while is finished to go with the structure?
Thank you very much for clearing me this doubt had already read some documentation but nothing that said with the clarity you answered, I believe that this answer will help other people.
– WMomesso
@Wagnerfernandomomesso I’m glad I was clear and helpful.
– Sergio