Jquery $.each sync

Asked

Viewed 107 times

0

I have a GRID on a screen where, each line has a button that calls a javascript method passing some values. In this method, a call is made via getJSON.

The problem is that even in this call, specifying async: false, the $.each does not wait to rotate the next line.

Follows the code of $.each:

console.log('start');
$('#btn_sugerir_todos').click(function(){

    $('.btnSugerir').each(function(index, value) {
        var def = new $.Deferred();
        var id        = $('#' + value.id).attr('data-id');
        var ordcol_id = $('#' + value.id).attr('data-ordcol_id');
        var data      = $('#' + value.id).attr('data-data');
        var hora      = $('#' + value.id).attr('data-hora');
        var cubagem   = $('#' + value.id).attr('data-cubagem');
        var fatexp_id = $('#' + value.id).attr('data-fatexp_id');
        console.log(id);

        sugerirVeiculo(jQPlanejador, id, ordcol_id, data, hora, cubagem, fatexp_id, false);
    });
    console.log('Fim');
});

All the console.log() are instantaneous in processing, but the actual result of the function sugerirVeiculo() is not.

Someone knows how forced to wait for the result line by line?

  • 3

    Where’s the asynchronous part? It’s the sugerirVeiculo? and where you use that def and why?

  • The def can ignore, does nothing. It was an attempt of mine to solve the problem.

  • Within the sugerirVeiculo, i use getJSON. I defined him with async: false but still, it’s asynchronous.

  • You can show the code of this sugerirVeiculo to better understand what it takes?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.