title: I'm trying to pass an array from controller to javascript by using ajax but it doesnt return as array it returns as a String
body: <p>Here is my code from controller:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  
  class AjaxController extends Controller
  {
  
      public function showOrder($id){
          $result = DB::select('select * from menu_tbl where id = ?', array($id));
          return json_encode($result);
      }
  }
  </code></pre>
  <p>Here is my code from javascript:</p>
  <pre class="lang-js prettyprint-override"><code>function addOrder(id){
      $.ajax({
          method: &quot;GET&quot;,
          url: &quot;/showOrder/&quot;+id,
          success: function (data){
              alert(data[&quot;name&quot;] + &quot; &quot; + data);
  
              //document.getElementById(&quot;name&quot;).innerHTML = data['name'];
              //document.getElementById(&quot;price&quot;).innerHTML = data['price'];
              //$(&quot;#buying&quot;).modal();
          },
      });
  }
  </code></pre>
  <p>Here is the result:</p>
  <pre class="lang-js prettyprint-override"><code>undefined [{&quot;id&quot;:1,&quot;name&quot;:&quot;Chicken Cordon Bleu&quot;,&quot;category&quot;:&quot;chicken&quot;,&quot;price&quot;:800,&quot;description&quot;:&quot;blah blah&quot;,&quot;img&quot;:&quot;img\/mcdonalds-burger.jpg&quot;,&quot;hot&quot;:0,&quot;spicy&quot;:0}]
  </code></pre>
  <p>the <code>data['name']</code> returns as <code>undefined</code> is there something wrong in my code? or the <code>DB:select</code> doesn't return array instead a String. I'm new at Laravel. Thanks for the help</p>