I have the below code, which increases a 'week' variable on the click of an arrow. It then uses the week variable to retrieve information from a PHP file (relevant to that week),
The 'week' variable updates on the first click. However the data retrieved from the PHP file doesn't update until the second click and therefore the data lags one week behind.
$('#fixtures-right-arrow').on('click', function(){
week++;
switch (week) {
case 1:
$.post("includes/fixture_1_home_lookup.php", {
home_1_league_position_id: home_1_league_position_id
}, function (data, status) {
home_team_1 = data;
});
break;
...
};
$('#fixtures-week').html(week);
$('#home-team-1').html(home_team_1);
});
It seems that the code is running the switch before it runs the week++. Is there a way that this can be avoided?
(I am experiencing a similar lag on every click event that retrieves data from a PHP file. One pop-up which accesses several different PHP files does not appear until the seventh click - and then appears perfectly, with all the data in place.
The PHP files all contain MySQL queries to retrieve data from a locally hosted database).