I want to get the json object via a ajax call. On using alert inside the call the alert show the expected result but when using the alert outside the block give 'undefined'. i want to use the same json object outside the block. if i using var result
, its also give the same result which i get from event_array
.
I am not getting what is the problem
var event_array;
var results;
get_app_cal();
function get_app_cal() {
jQuery.ajax({
url:'<?php echo site_url();?>/xyzController/xyz_cal',
type:'POST',
dataType: "JSON",
success:function(results) {
//alert(results);
//event_array = JSON.stringify(results)
event_array = results;
console.log(event_array);
alert(event_array) // its show the required value (work perfectly)
}
});
}
alert(event_array) // return undefined (Not working not showing required value)