title: JQuery AJAX: Get a PHP array AND assign it to a Javascript variable
body: <p>My problem should be very easy to resolve, I just can't get it together.</p>
  
  <p>I have a simple working php file. It retrieves data from a database and assigns it to an array. It does not requires parameters and such. It gives a straight array: <br><br>
  <strong>PHP</strong></p>
  
  <pre><code>...PDO connection code...
  ...SQL code....
  
  $query = $dbc-&gt;query($sql);
  $db_data = $query-&gt;fetchAll();
  
  //I added the code below to send to JQuery:
  echo json_encode($db_data);
  </code></pre>
  
  <p>No problems here, it gives me a nice multidimensional array</p>
  
  <p><strong>The problem is in my JQuery:</strong></p>
  
  <pre><code>$(document).ready(function () {
      var ajaxURL = 'ajax.php';
      var ajaxData = {};
  
      $.get(ajaxURL, function (data) {
          ajaxData = data;
      });
  
          //For testing
          alert( ajaxData );
  
          //JQuery code to be used with ajaxData...
  });
  </code></pre>
  
  <p><code>$.get</code> is retrieving the array, without problems. <code>data</code> is 100% OK, but...
  When I want to use <code>ajaxData</code> it's empty or undefined (if I remove <code>var ajaxData = {};</code>). I need <code>ajaxData</code> to get the contents of <code>$db_data</code> to use on other stuff latter on.</p>
  
  <p><strong>The core of the problem is:</strong> 
  JQuery loads and runs all the other code first (Past <code>$.get</code>). And THEN, it runs <code>$.get</code> code last. How can I get it to run <code>$.get</code> FIRST, and then to run whatever code is below? Is that what you call a synchronous ajax request?</p>