I have the following functions:
Gets server data by ajax and saves it to an Array of objects:
function carregaPesquisaTabela(){
controlLoading();
$.ajax({
url: "header.php",
type: "POST",
dataType:"json",
data: {
'procuraPesquisa' : null
}
}).done(function(data){
pesquisaObj = data;
controlLoading();
});
}
Get the Object Array and mount a table. (I will not put all the code because it is not necessary)
function montaTabela(){
$("#tablePesquisas").empty();
var linha = "";
for(i = 0; i<pesquisaObj.length; i++){
//Monta dados e insere em uma tabela
$("#tablePesquisas").html(linha);
}
}
I call them both as follows:
$("#viewPesquisa").submit(function(e){
e.preventDefault();
carregaPesquisaTabela();
montaTabela();
});
The problem is that the action setsTable (); is happening before the function loadsSearchTable (); being finished, and so the result is not being real.
I saw something about callback but I could not implement it. What to do?