Can't store to a global vaiable
I am calling a PHP script and trying to store the results to a Global Variable for use in later functions. But It doesn't seem to be saving the results to the variable. I have found, that within the ajax success call it will display the proper information. Outside of the AJAX success (whether in the function or outside of it) the variable is listed as undeclared.
- Info={};
- $(function(){
- GetInfo();
- console.log('After GetInfo() in Main: '+Info);
- console.log('Info[\'GotInfo\']='+Info['GotInfo']);
- console.log('Info[\'InfoInt1\']='+Info['InfoInt1']);
- console.log('Info[\'InfoString\']='+Info['InfoString']);
- console.log('Info[\'InfoInt2\']='+Info['InfoInt2']);
- function GetInfo(){
- $.ajax({
- type:'GET',
- url:'GetInfo.php',
- datatype:'json',
- error:function(XMLHttpRequest, textStatus, errorThrown){
- console.log('Error with AJAX Request');
- console.log(XMLHttpRequest);
- console.log(textStatus);
- console.log(errorThrown);
- },
- success:function(data){
- Info=$.json.decode(data);
- console.log('In Function GetInfo(): '+Info);
- console.log('Info[\'GotInfo\']='+Info['GotInfo']);
- console.log('Info[\'InfoInt1\']='+Info['InfoInt1']);
- console.log('Info[\'InfoString\']='+Info['InfoString']);
- console.log('Info[\'InfoInt2\']='+Info['InfoInt2']);
- },
- });
- }
- });