I have a mobile application under development using Cordova
, which performs a select on my external DB and checks with the mobile data so knowing if there is any change in the given.
I am using a request via AJAX
. The correct operation would be, the app checks if there is a change if it has something different it runs a UPDATE
on my BD mobile, then it would have to mount a table with the information for the user to view.
But it does not expect the return of AJAX
to know if there are changes, it simply calls the function and assembles the table. When I inspect line by line it even waits for the AJAX return, but it does not let the function call be performed to make UPDATE
on the BD mobile.
Here is my code below:
atualizarTabela: function (tx, results) {
var len = results.rows.length;
if (conectado == 1) { Verificação se existe conexão com internet
for (var cont = 0; cont < len; cont++) {
var prazo = results.rows.item(cont).prazo;
var statusBD = results.rows.item(cont).status;
var nomeDepartamento = results.rows.item(cont).nomeDepartamento;
var protocolo = results.rows.item(cont).protocolo;
var serviceURL = "http://192.168.0.104:18376/Solicitacao/SelectAtualizacao";
var parametros = { id: protocolo }
$.ajax({
type: "GET",
url: serviceURL,
data: parametros,
async: false, // Tentei colocar async false mas não resolveu
success: function (data) {
alert("Retorno Ajax ok");
if (data[0].prazo != prazo || data[0].status != statusBD || data[0].id_departamento != nomeDepartamento) { //Verifica se existe alterações
db.transaction(select, errorCB, sucess);
function select(tx) { //Este seria o meu Update no bd local
tx.executeSql('UPDATE ouvidoria11 set prazo = "' + data[0].prazo + '", status = "' + data[0].status + '", nomeDepartamento = "' + data[0].nomeDepartamento + '" WHERE protocolo="' + protocolo + '"');
app.selectDB();
}
function errorCB() {
alert("ERROCB");
}
function sucess() {
alert("Atualizado!");
}
}
}
});
}
app.montarSolicitacao(tx, results);
}
else { //Caso não tenha internet, monta tabela sem verificação de Atualização
app.montarSolicitacao(tx, results);
}
},