I'm using global javascript variables to store some data after an Ajax request. It's used to mark days on a jqueryui datepicker and are stored in the form array[date] = type_of_date
this is the function i'm using to compute the array(s)
function get_date_exceptii(data, cod_calendar) {
if(typeof(window.date_zile_ore_modificate) !== 'undefined' && typeof(window.date_zile_nelucratoare) !== 'undefined') {
window.date_zile_ore_modificate.length = 0;
window.date_zile_nelucratoare.length = 0;
}
else {
window.date_zile_ore_modificate = [];
window.date_zile_nelucratoare = [];
}
parametri = 'cod_calendar='+cod_calendar+'&data='+data;
$j.ajax({
url: "proiecte/ajax/colectare_date_exceptii.php?sid="+Math.random(),
type: 'POST',
async: false,
data: parametri
})
.done( function (msg) {
arr_msg = msg.split('[sep1]');
$j.each(arr_msg, function (index, val) {
arr_exceptie = val.split('[sep]');
if(arr_exceptie[1] == 'nelucratoare')
window.date_zile_nelucratoare[arr_exceptie[0]] = arr_exceptie[2];
else {
window.date_zile_ore_modificate[arr_exceptie[0]] = arr_exceptie[2];
}
});
});
console.log(window.date_zile_ore_modificate);
console.log(window.date_zile_nelucratoare);
}
The two logs are for debugging, of course. The problem is the the arrays are never cleared even tho that section of code is executed. Is my syntax wrong or am I missunderstanding global variables and/or arrays here?