title: Sending data from Jquery to Controller 500 internal error
body: <p>Yes, I have come across this error in the past and it has to do with the csrf token, but in the past I just went to the Middleware VerifyCSRF file and included the route in the list of ignores.</p>
  
  <p>However this is not working now. And I am puzzled.</p>
  
  <p>The only difference I can think of is that the first time I had it on production in a server while now I am coding in cloud9 and it uses https but, since firefox gives problem when you have vulnerable code inside a https page, I deactivated that, otherwise nothing on the site would display. But that shouldn't have anything to do.</p>
  
  <p>Another thing that baffles me is the fact that on loading the page, I can already see in firebug the 500 error, but this should be only activated on changing the select list, however it does happen just on page load also.</p>
  
  <p>Here is the full code:</p>
  
  <p>I have this in a partial since it is going to be used by 2 pages:</p>
  
  <pre><code>     &lt;script&gt;        
        jQuery(document).ready(function () {
      cargarProvincias();
   //   cargarCiudades();
      $('#country').change(cargarProvincias);
      $('#regions').change(cargarCiudades);
  
       });
  
          function cargarProvincias() {            
          var country = $('#country').val();  
            $regionsurl = "{{URL::route('findcountries')}}";
  
            $.post($regionsurl, {country:country},function(data){
                  $('#regions').empty();                 
                  $.each(data, function(key, value){                 
                  $('#regions').append('&lt;option value="' + key + '"&gt;' + value + '&lt;/option&gt;')});
                      cargarCiudades();         
                });
            }
  
            function cargarCiudades(){     
  
            // alert("You have Selected  :: "+$(this).val());
              var region = $('#regions').val();
            $url = 'http://chefvillas.com/localidades';
            $.post($url, {localidad:region},function(data){           
                  $('#towns').empty();                 
                  $.each(data, function(key, value){
                  var option = $('&lt;option/&gt;', {'id':key, 'text':value});
                  $('#towns').append(option);
                  });                 
                });               
            }   
      &lt;/script&gt;  
  </code></pre>
  
  <p>Then this is the route:</p>
  
  <pre><code>Route::get('/', 'SearchController@welcome');
  Route::post('/', ['as' =&gt; 'findcountries','uses'=&gt;'SearchController@findcountries' ]);
  </code></pre>
  
  <p>And this is the controller</p>
  
  <pre><code> public function welcome(){
        $countries = Property::distinct()-&gt;select('country')-&gt;get();
        return view('welcome', ['countries' =&gt; $countries]);
    }
  
  
    public function findCountries(){
      $pais = Input::get('country');
      print_r($pais); // but I never get here because the error blocks it before
  
     }  
  </code></pre>
  
  <p>I have tried this too, but no change in feedback</p>
  
  <pre><code>public function findCountries(){
  
        if (Request::ajax())
  {
      $pais = Input::get('country');
        var_dump($pais);
  }
  </code></pre>
  
  <p>I have been so far a full day stuck with this. I have tried to change the syntax of the route, despite the fact that this is the same code that I used in the past.</p>
  
  <p>UPDATE</p>
  
  <p>Here the Network tab status confirms that it is a csrf error: (Token Mismatch Exception) </p>
  
  <p>but I have added the URI to the list of ignores</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
  class VerifyCsrfToken extends BaseVerifier
  {
      /**
       * The URIs that should be excluded from CSRF verification.
       *
       * @var array
       */
      protected $except = ['findcountries'];
  }
  
  TokenMismatchException in VerifyCsrfToken.php line 67:
  in VerifyCsrfToken.php line 67
  at VerifyCsrfToken-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
  at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 62
  at StartSession-&gt;handle(object(Request), object(Closure))
  at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
  at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure))
  </code></pre>
  
  <p>UPDATE 2</p>
  
  <p>I have included this in a separate file</p>
  
  <pre><code>// public/js/config.js
  $(function () {
      $.ajaxSetup({
          headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') }
      });
  });
  </code></pre>
  
  <p>And also this metatag</p>
  
  <pre><code>&lt;meta name="csrf-token" content="{{ csrf_token() }}" /&gt;
  </code></pre>
  
  <p>However, one thing that I keep gettin Warned about all the time is little triangles in orange color saying:</p>
  
  <pre><code>$ is not defined; please fix or add/* global $*/
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/iBfGf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iBfGf.png" alt="enter image description here"></a></p>
  
  <p>But it is not just about jquery (because it is installed and it works because I have a working slider) but about any line that contains an $. If it is $url it will say url is not defined.</p>