I have a function in jquery that has a while that writes data to the database, and after this while it prints to console that the data has been saved, the function looks 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);
}
On the console it appears that the data has been saved and the current position of the x is 7, ie it saved the 6 lines in the database, but my question is the following because the console.log
from within while
is printed last ?
As seen in the image it writes the data but prints the console in reverse, this is due to the delay of recording the data in the database, or if I insert another function in place of the last console I can have problems the data do not have finished and perform the other function? For now it is working, but I have this doubt, or is there a way to check if the while is finished to continue with the structure?