this is my code, which works not perfectly yet:
function func1() {
$('.lastStateText').html("<img src='images/Loading.gif' />").fadeIn('slow')
$('.lastStateText').each(function() {
lastState('xxx').then(result =>
$( this ).fadeOut(500, function(){
$( this ).text(result)
alert(result)
})
)
})
}
function lastState(parameter) {
return new Promise( done =>
$.getJSON("myFile.php", {
parameter: parameter
}, function(result) {
done(result);
}
)
)
}
What happens here?
- I call func1
- This function will show a Loading.gif in each element with the class "lastStateText" with a fadIn effect
- A loop will go through all lastStateText elements, fadeOut it out and call each time the next function lastState with a parameter 'xxx'. 4 The lastState function will get the result of myFile.php and give it back to the func1.
- Now the func1 should set the result into the lastStateText element <- but this doesn't work. now result will shown in the element. I checked with alert(result) if the result will be available and yes -> the result is there. but not visible in my lastStateText element.
Where is my fault?