I have at ready a function with inside ajax
call that extrapolates values from MySql database.
Then, in .scroll()
event, i have a function that use thise values to animate some divs
.
The problem is that sometimes .scroll()
is run when ajax call is not finished.
function values_database(){
$.ajax({
type: "POST",
url: 'events.php',
dataType:"json",
data: {
dal_mese1: 'example'
},
success: function (result) {
var return_php = JSON.parse(JSON.stringify(result));
values.push(return_php); //VALUES FOR ANIMATIONS
}
}
$(window).scroll(function(){
var top_window2 = $(window).scrollTop();
var bottom_window2 = top_window2 + $(window).height();
var top_statistiche = $('#somedivs').offset().top;
if(((top_statistiche >= top_window2) && (top_statistiche <= bottom_window2))){
animation_somedivs();
}
});
function animation_somedivs(){
//use values global array (with inside value from database, if ajax call is finish before "this" function is run
}
How can i solve this problem ?
(I don't want to use async: false
)
Thanks a lot and sorry for my english