title: display data using Ajax in laravel
body: <p>I'm trying to fetch the data from the database from a table 'Company' in the output it coming as a json format,i have to display it in a Data Table.</p>
  
  <blockquote>
    <p>Controller</p>
  </blockquote>
  
  <pre><code>public function ex(Request $request){
      $table =  \DB::table('company')-&gt;select('name','type','address','city','email','description')-&gt;get();
      //return view('mydata')-&gt;with('company',$table);
      return response($table);
  }
  </code></pre>
  
  <blockquote>
    <p>Route</p>
  </blockquote>
  
  <pre><code>Route::get('display','Test@ex');
  </code></pre>
  
  <blockquote>
    <p>Blade page</p>
  </blockquote>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      $(document).ready(function(){
          $("button").click(function(){
             $("table").toggle();
             $.get("{{URL::to('display')}}",function (data) {
                 $.each(data,function (i,value) {
                   var  tr =$("&lt;tr/&gt;");
                   tr.append($("&lt;td/&gt;",{
                       text : value.name /*Get first column*/
                   }))
                 })
             })
          });
      });
      &lt;/script&gt; 
  &lt;/head&gt; 
  
  &lt;body&gt; 
  &lt;button&gt;Click Me&lt;/button&gt; 
  &lt;table border="1px" class="table table-striped table-bordered" style="width:100%"&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Type&lt;/th&gt;
          &lt;th&gt;Address&lt;/th&gt;
          &lt;th&gt;City&lt;/th&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt; 
      &lt;/table&gt; 
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>the output  coming as in following image but i want to display it in a Datatable</p>
  
  <p><a href="https://i.stack.imgur.com/hna5k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hna5k.jpg" alt="output in JSON format "></a></p>