$ .get callback is not called and I can not debug to find out the reason

3

I'm developing a mobile application (with cordova) that needs to do a select in the BD online, and with this data update the mobile phone's DB, however I came across a problem, I perform the select in the DB of the mobile phone after performing a

$.get(url, parametro, fuction(data){
});

to select the database online, and in the verification check if the data is different and if I do the update, but when I give a Debug it does not enter into my get I was told that this happens because it is a SUBSCRIBE function but I do not know how to solve this.

My code:

    queryDB: function (tx) {
        tx.executeSql('SELECT * FROM ouvidoria11', [], app.querySuccess3, app.errorCB);
    },
querySuccess3: function (tx, results) {
        var len = results.rows.length;
        var protocolo;
        var tblText = '';
        if (len < 1) {
            alert("Não existe nenhum cadastro!");
        }
        else {
            for (var i = 0; i < len; i++) {
                if (results.rows.item(i).protocolo == null) {
                    app.protocoloSolicitacao(results.rows.item(i).id, results.rows.item(i).assunto, results.rows.item(i).mensagem, results.rows.item(i).endereco, results.rows.item(i).anexo);
                }
                tblText += '<span onclick="app.guardaVariavel('+results.rows.item(i).protocolo+')"><table id="t01" class="table-bordered">';
                tblText += '<tr><th>Protocolo</th><td>' + results.rows.item(i).protocolo + '</td></tr>';
                tblText += '<tr><th>Assunto</th><td>' + results.rows.item(i).assunto + '</td></tr>';
                tblText += '<tr><th>Mensagem</th><td>' + results.rows.item(i).mensagem + '</td></tr>';
                tblText += '<tr><th>Endereco</th><td>' + results.rows.item(i).endereco + '</td></tr>';
                tblText += '<tr><th>Anexos</th><td>' + results.rows.item(i).anexo + ' </td></tr>';
                tblText += '<tr><th>Prazo</th><td>' + results.rows.item(i).prazo + '</td></tr>';
                tblText += '<tr><th>Status</th><td>' + results.rows.item(i).status + '</td></tr>';
                tblText += '<tr><th>Departamento</th><td>' + results.rows.item(i).nomeDepartamento + '</td></tr>';
                tblText += '</table></span>';
                document.getElementById("tabelaSolicitacao").innerHTML = 

tblText;
                    var protocolo = results.rows.item(i).protocolo;
                    var nomeDepartamento = results.rows.item(i).nomeDepartamento;
                    var prazo = results.rows.item(i).prazo;
                    var statusBD = results.rows.item(i).status;
                    app.atualizarTabela(prazo, statusBD, nomeDepartamento, protocolo);//Chama a função para atualizar os dados
                }
            }
        },
atualizarTabela: function(prazo, statusBD, nomeDepartamento, protocolo){    
        var serviceURL = "http://ouvidoria.azurewebsites.net/Solicitacao/SelectAtualizacao";
        var parametros = { id: protocolo }
        $.get(serviceURL, parametros, function (data) {
            alert("Teste Get");
            if (data[0].meuPrazo != prazo || data[0].status != statusBD || data[0].nomeDepartamento != nomeDepartamento) {
                db.transaction(update, null, null);
                function update(tx) {
                    tx.executeSql('UPDATE ouvidoria11 set prazo = "' + prazo + '", status = "' + statusBD + '", nomeDepartamento = "' + nomeDepartamento + '" WHERE protocolo="' + protocolo + '"');
                }
            }
        });
    },

Note: As stated, it even calls the atualizarTabela() function but does not enter $.get , nor does it even display alert(''); , it displays alert() after for function querySucess3() it displays it several times, exactly the number of times the atualizarTabela() function was called in for of the main function querySucess3()

The meuPrazo is returning of undefined when I put it to debugar console.log (data) it returns the following:

Object
abort: function ( statusText ) {
always: function () {
complete: function () {
done: function () {
error: function () {
fail: function () {
getAllResponseHeaders: function () {
getResponseHeader: function ( key ) {
overrideMimeType: function ( type ) {
pipe: function ( /* fnDone, fnFail, fnProgress */ ) {
progress: function () {
promise: function ( obj ) {
readyState: 4
responseJSON: Array[1]
responseText: "[{"id":0,"assunto":null,"mensagem":null,"endereco":null,"anexo":null,"status":"Aguardando","meuPrazo":"Indefinido","nomeDepartamento":null,"id_departamento":2}]"
setRequestHeader: function ( name, value ) {
state: function () {
status: 200
statusCode: function ( map ) {
statusText: "OK"
success: function () {
then: function ( /* fnDone, fnFail, fnProgress */ ) {
__proto__: Object
    
asked by anonymous 01.07.2015 / 17:56

1 answer

0

Pass the async: false parameter in ajax should solve, I'll demonstrate an example:

$.ajax({type:"GET", url:view, dataType:"json", data:data,async:false,              // FAZ UM AJAX SINCRONIZADO COM A FUNCAO
        success: function(json) { retorno = json; },                                    // RETORNO DO AJAX NO SUCCESS
        error: function(json) { retorno=json; },                                        // RETORNO DO AJAX NO ERROR
        beforeSend: function() { $('body').css('cursor','wait'); },                     // RETORNO DO AJAX NO ERROR
        complete: function(){ $('body').css('cursor','default'); }
    }); 

You have a question like this here link

EDIT: in your code above it would look like this to find out if there is any return value:

$.ajax({type:"GET",url:serviceURL,data:parametros, async:false,
    complete: function (data) {
        console.log(data);
    }
});
    
02.07.2015 / 15:11