title: Jquery ajax returns data sorted
body: <p>I have a php script that fetches data from a DB, the result set is returned in a particular order, e.g. </p>
  
  <p><code>Name: John, Age: 21, Address: 1234 Fifth Ave.</code></p>
  
  <p>I verified the order while debugging.  The result set is then pushed into an array, which is then encoded as a json object and passed to my jquery script through an AJAX request.  </p>
  
  <pre><code>var resultSet = [];
      $.ajax({
          async: false,
          url: 'scripts/getData.php,
          dataType: "json",
          success: function(data) {
          /* Store the pieces of the array */
          resultSet = data["php_resultSet"]; //&lt;--Breakpoint here shows the resultSet sorted, if order is preserved here, my problem will be solved.
      }
      });
  </code></pre>
  
  <p>However, when I get my data back and analyze the array, it is sorted, e.g.</p>
  
  <p><code>Address: 1234 Fifth Ave., Age: 21, Name: John Age: 21</code></p>
  
  <p>I want to preserve the order of the original result set, is there an option I have to set in order to do that?  Help is appreciated.</p>
  
  <p>UPDATE:</p>
  
  <p>Here is a snippet of the PHP code that builds the array and encodes it</p>
  
  <pre><code>    $data = array ( "otherData" =&gt; array(), "php_resultSet" =&gt; array() );
  
      while ( $row = sqlsrv_fetch_array ( $stmt, SQLSRV_FETCH_ASSOC ) ) {
          //Push the entire row to the result set array
          array_push ( $data["php_resultSet"], $row );
      }
  
      asort($someData);
  
      foreach ( $someData as $key) {
          array_push ( $data["otherData"], $key );
      }
  
  return json_encode($data);//&lt;--At this point, even though the I sorted $someData before pushing it to the $data, the php_resultSet maintains its sorted order.
  </code></pre>