I have 2 functions that should run one after another. I am implementing a callback in the first one, but it looks like something (I think the getJSON or the forEach) inside this function is messing around.... here is the code :
function one (param1, param2, callback)
{
...
$.getJSON(...function(data){});
my_array.forEach(function(item){...});
if(callback) callback();
}
function two ()
{
...
}
Then I call the function this way :
one(value1, value2, two)
When I do that, I notice that my function two is using some values that have not yet been processed by function one.... I could put function two in the callback of the getJSON, but I must have the forEach performed two....
What am I doing wrong ?
EDIT :
var next = function (item, id) {
item = item.substr(2);
item = item.substr(0, item.length - 2);
$('#popup_generate').html(item + ' <input type="text" id="question_answer" name="question_answer"><br><br><button class="close">Valider</button>');
$('#popup_generate').fadeIn().css({'width': 400});
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter': 'alpha(opacity=70)'}).fadeIn();
$('.close, #fade').click(function () {
answer = $('#question_answer').val();
inputText = inputText.replace('[[' + item + ']]', answer);
tinyMCE.activeEditor.setContent(inputText);
if(++id < resultArray.length) {next(resultArray[id], id);} else {$('#fade , .popup_block').fadeOut(function () {$('#fade, .close').remove();});}
});
};
next(resultArray[0], 0);