JQuery Each function with ajax loop -
hello guys first post in forum.
i have function
function testepresenca(){ var msg = '' $('#teste tbody tr').each(function(){ var memberid; var classid; var presencedate; var oclasse; var datapre = $('#data_presenca').val(); var totbiblia = $('#tot_biblia').val(); var totoferta = $('#tot_ofertas').val(); $(this).find('td').each(function(){ if($(this).index() == 0){ memberid = $(this).text(); } if($(this).index() == 3){ $(this).closest('tr').find("select").each(function(){ classid = this.value; }) } if($(this).index() == 4){ oclasse = $(this).text(); } }); $.ajax({ type: 'post', url: base + '/save_list_presence', data: {pmemberid: memberid, pclassid: classid, poclasse: oclasse, pdatapre: datapre, ptotbiblia: totbiblia, ptotoferta: totoferta}, success: function(retorno){ msg += retorno; }, error: function(xhr, ajaxoptions, thrownerror) { alert('erro!'); } }); }); alert(msg);} my problem "alert(msg)" fires without message, in debug time see fire each , ajax execute after , "msg" variable pupulated @ end, alert fired before.
anyone have idea how can fix it?
thanks in advance.
try use async: false in ajax call:
$.ajax({ type: 'post', url: base + '/save_list_presence', async: false, ... by default, requests sent asynchronously (i.e. set true default). if need synchronous requests, set option false. cross-domain requests , datatype: "jsonp" requests not support synchronous operation. note synchronous requests may temporarily lock browser, disabling actions while request active.
Comments
Post a Comment