title: Returning json results at the same page in laravel
body: <p>I have trouble returning my search results as json in same page that I searched,</p>
  
  <p>this is my function for <code>search page</code></p>
  
  <pre><code>public function track(Request $request){
      return view('front.track');
  }
  </code></pre>
  
  <p>this is <code>route for it</code>:</p>
  
  <pre><code>Route::get('/track', 'frontend\FrontendController@track')-&gt;name('track');
  </code></pre>
  
  <p>and this function to <code>get results of my search</code></p>
  
  <pre><code>public function shippingcode(Request $request){
      $rajaongkir = new Rajaongkir\Domestic('xxxxxxxxxxxxxxxxxxxxxxxxxxx');
      $shippingcode = $request-&gt;input('shippingcode');
      $item = Order::where('shippingcode', $shippingcode)-&gt;first();
      $courier = $item-&gt;courier;
      $results = $rajaongkir-&gt;waybill($shippingcode, $courier);
      return response()-&gt;json($results);
    }
  </code></pre>
  
  <p>and this is <code>route for it</code>:</p>
  
  <pre><code>Route::post('/shippingcode', 'frontend\FrontendController@shippingcode')-&gt;name('shippingcode');
  </code></pre>
  
  <p>and finally this is my <code>search form</code> in blade:</p>
  
  <pre><code>&lt;form class="form-inline text-center" action="{{route('shippingcode')}}" method="post"&gt;
    {{csrf_field()}}
    &lt;lable&gt;Shipping Code #&lt;/lable&gt;
    &lt;input type="text" class="form-control" name="shippingcode" placeholder="93657275025"&gt;
    &lt;button class="btn btn-success" id="submit" type="submit" name="button"&gt;Track&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <h1>Issue</h1>
  
  <p>Issue is except getting results bottom of my form I will redirect to another page and see results as JSON.</p>
  
  <p>any idea?</p>
  
  <h1>UPDATE</h1>
  
  <p>I have added jquery to my page in order to get results but still i will redirect to another page:</p>
  
  <p><code>JavaScript</code></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
      $('button[id="submit"]').on('click', function() {
        $.ajaxSetup({
            headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') }
        });
  
  
        $.ajax({
          url: '{{ url('shippingcode') }}',
          type: "GET",
          dataType: "json",
          success:function(data) {
              $('div#results').empty();
              $("div#results").html(data);
          }
        });
  
      });
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>and added this div bottom of my form <code>&lt;div class="col-md-8 col-md-offset-2" id="results"&gt;&lt;/div&gt;</code></p>