title: laravel pass data from controller to jquery using json
body: <p>I want to pass data from controller to jquery using json don't know where is the problem but fro the jquery code I think its working fine as I tested the success code but can't get back the result from controller</p>
  
  <p><strong>home.blade</strong></p>
  
  <pre><code>    &lt;form role="form" name="form_address" id="form_address" action="" method="POST"  enctype="multipart/form-data"&gt;
       {{ csrf_field() }}
    &lt;input type="text" id="postal_code" onFocus="geolocate()"&gt;
    &lt;input type="text" id="totaldistance"  onFocus="geolocate()"&gt;
   &lt;/form&gt;
    &lt;button id="save_address"&gt;Save&lt;/button&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code> &lt;script&gt;
  $("#save_address").click(function (e) {
  $.ajaxSetup({
      headers: {
           'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
      }
     });
  
     e.preventDefault();
    var form = document.forms.namedItem("form_address");
    var formData = new FormData(form); 
    $.ajax({
       type: "get",
      url: 'Get_distance',
      contentType: false,
      data: formData, 
      processData: false,
      success: function(data) {
        $('#totaldistance').val(data.distance); 
      }
     });
    });
  </code></pre>
  
  <p><strong>web.php</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>Route::post('Get_distance','HomeController@getdistance');
  </code></pre>
  
  <p><strong>controller</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>public function getdistance(Request $request)
  {
    $distance =$request-&gt;postal_code;
  
    return Response::json(array(
      'distance' =&gt; $distance,  
    ));
  }
  </code></pre>