title: jquery async and JSON data
body: <p>following from <a href="https://stackoverflow.com/questions/5484193/javascript-jquery-and-using-eval">javascript jquery and using eval</a> i still could not get jquery to read the data asynchronously.</p>
  
  <pre><code> data1=[1,2,3,4]
  </code></pre>
  
  <p>Note: i have included async:true in the below example just to show the difference</p>
  
  <p>Below example return "null"</p>
  
  <pre><code>$(document).ready(function(){
  
  var myArray=[];
  myArray=getValues();
  alert(myArray);
          function getValues(){
          var result=null;
               $.ajax({
                  url: 'data1.html',
                  type: 'get',
                  dataType: 'json',
                  cache: false,
                  success: function(data) {result = data;},
                  async:true,
                  });
              return result;
          };
  })
  </code></pre>
  
  <p>and below example work fine and gives the result in an array i.e [1,2,3,4]</p>
  
  <pre><code>$(document).ready(function(){
  
  var myArray=[];
  myArray=getValues();
  alert(myArray);
          function getValues(){
          var result=null;
               $.ajax({
                  url: 'data1.html',
                  type: 'get',
                  dataType: 'json',
                  cache: false,
                  success: function(data) {result = data;},
                  async:false,
                  });
              return result;
          };
   })
  </code></pre>
  
  <p>can someone explain how to get the results asynchronously 
  Thanks</p>