title: pass php array to javascript using ajax
body: <p>I try to get array from sql server using php , and parsing these array to javascript using ajax.
  However , I have tried many solution by google , I can't get the array.</p>
  
  <p>This is my php code:</p>
  
  <pre><code>&lt;?php
      include 'Connect.php';
      $Store_int = $_GET['num'];
  
      $sql = "SELECT * FROM `store` WHERE `Place_int` = " . $Store_int;
  
      mysqli_select_db($link, "web");
      $link-&gt;set_charset("utf8");
      $result = mysqli_query($link, $sql);
  
      $arr = array();
      while ($row = mysqli_fetch_object($result)) {
          $p = (string)$row-&gt;Name;
          $arr[] = $p;
      }
      //print_r($arr);
      $jsonArr = json_encode($arr, JSON_UNESCAPED_UNICODE);
      echo $jsonArr;
      mysqli_free_result($result);
      mysqli_close($link);
  ?&gt;
  </code></pre>
  
  <p>Array in php will encode and display:</p>
  
  <pre><code>["pen","pencil","apple","cat","dog"]
  </code></pre>
  
  <p>and the .js file</p>
  
  <pre><code>function getArr(store_int) {
      var jsArray = new Array();
      $.ajax({
          url: "fromSQL_store.php",
          data: {
              num: $("#store_int").val()
          },
          type: "GET",
          dataType: "json",
          success: function (data) {
              alert(num);
              jsArray = JSON.parse(data.jsonArr);
          }, error: function (data) {
              alert("123");
          }
      });
      //alert(jsArray.length);
      return jsArray;
  }
  </code></pre>
  
  <p>In .js , I will always get empty response(undefined) from php.
  Because the ajax will answer "error" function..., and the error status is 200.</p>