0
I need to call a function in jQuery, but it has to wait for another function to finish, because it depends on the result of the first function to work. I’m using the jQuery.
Follow the first passage:
$(function(){
$('#id_gestora').each(function(){
if( $(this).val() ) {
$('#id_projeto').hide();
$('.carregando').show();
$.getJSON('_model/popularprojeto_gestoraprojeto.php?search=',{id_gestora: $(this).val(), ajax: 'true'}, function(j){
var options = '<option value="">Selecione um projeto</option>';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].id_projeto + '">' + j[i].descricao_projeto + '</option>';
}
$('#id_projeto').html(options).show();
$('#id_projeto').val('<?php echo $projeto_calendariocontabilfundo_edit; ?>');
$('.carregando').hide();
});
} else {
$('#id_projeto').html('<option value="">Selecione um projeto</option>');
$('#id_projeto').show();
}
});
});
And the second, which depends on the previous:
$(function(){
$('#id_projeto').each(function(){
if( $(this).val() ) {
$('#id_calendariocontabil').hide();
$('#id_calendariocontabil').html('<option value=""></option>');
$.getJSON('_model/popularcalendariocontabil_projeto.php?search=',{id_projeto: $(this).val(), ajax: 'true'}, function(j){
$('#id_calendariocontabil').show();
var options = '<option value="">Selecione um </option>';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].id_calendario + '">' + j[i].descricao_calendario + '</option>';
}
$('#id_calendariocontabil').html(options).show();
$('#id_calendariocontabil').val('<?php echo $calendario_calendariocontabilfundo_edit; ?>');
$('.carregando').hide();
});
} else {
$('.carregando').hide();
$('#id_calendariocontabil').html('<option value="">Selecione um calendário contábil</option>');
}
});
});
Thank you very much Luiz Felipe, it worked correctly, vlw by force... Saw if I need to call one more Function along with the second. Ex.: we continue with the same scenario, the first wheel Function, as soon as it finishes we are running the second... Could it run a third Function along with the second? can be at the same time as the second.
– Junior Cunha
In this case you pass an anonymous function as callback and calls the second and third inside that anonymous. I edited the question...
– Luiz Felipe
If I understand correctly, create a Function with a generic name, put the second and third Function within this generic function... Oh yes I call that generic Function in callback. Would that be?
– Junior Cunha
It worked, kkkk
– Junior Cunha
Luiz Felipe, thank you very much bro... Very fast and effective. Gave bless your day.
– Junior Cunha