title: How to return data to variable after ajax call success
body: <p>I have a PHP file returning data in required array format to my FlotChart, it's working.
  Now I'm trying to get this result in my script using ajax, however I cannot see result on global variable, as described below:</p>
  
  <pre><code>myJS.js   
  var EcomDashboard = function() {
      return {
          init: function() {
  
          var dataEarnings = NULL;
  
          $.ajax({
              url:"operation.php",
              dataType: "text",  
              success:function(data) {
                  alert(data); //show my array [ [1, 20],[2,30],[3,14] ] 
                  dataEarnings = data;
              }
          });
  
          alert(dataEarnings); //showing "NULL" but I need [ [1, 20],[2,30],[3,14] ]
  
          ...
  </code></pre>
  
  <p>What is the correct way to assign to my variable date Earnings the array [[1, 20], [2.30], [3.14]]?</p>