I have an ajax function:
$.ajax({
url: 'http://localhost/process.php',
type: 'post',
data: '',
success: function(output) {
var animal = output
}
});
I would like the var animal to be set globally so I can call it anywhere on the page even outside the ajax function's success callback. How to do this?
$.ajaxcall is asynchronous. I can sense a "why is animal undefined?" around the corner. ;o)console.log(typeof animal);//possibly returns undefined due to uninitialized.