title: Laravel 4: manipulating ajax data through controller
body: <p>I'm new at Laravel and ajax. I'm trying to get the data from a form via ajax and calling a method in the controller via that same ajax. The method in the controller searches the database and then returns a json response that gets handled by ajax(that last part I'm still thinking about, I haven't really done it yet).
  Let me show you what I have now:</p>
  
  <p>Routes.php:</p>
  
  <pre><code>Route::get('/', 'HomeController@getIndex');
  Route::post('/', 'HomeController@postIndex');
  </code></pre>
  
  <p>HomeController:</p>
  
  <pre><code>public function getIndex()
  {
      return View::make('index');
  }
  
  public function postIndex()
  {
      $match = Input::get('search');
      $results = Customers::where('name', 'like', '%'.$match.'%')-&gt;get(); 
      return Response::json(array('results' =&gt; $results));
  }
  </code></pre>
  
  <p>And my index.blade.php View :</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function() {
      $('form#find').submit(function() {
          $.ajax({
              url : 'CustomerSearch/Public',
              type: 'post',
              dataType: 'json',
              data: $('form#find').serialize(),           
          });
          return false;
      });
  }); 
  </code></pre>
  
  <p></p>
  
  <p>and the form:</p>
  
  <pre><code>    {{ Form::open(array('url' =&gt; '', 'method' =&gt; 'POST', 'id' =&gt; 'find')) }}
      {{ Form::text('search', '', array('class' =&gt; 'search-query', 'placeholder' =&gt; 'Search')) }}
      {{ Form::submit('Submit', array('class' =&gt; 'btn btn-info')) }}
      {{ Form::close() }}
  </code></pre>
  
  <p>So I should be getting the data from the form then sending it to the "postindex" method in the controller so it gets processed and then sent back, right? Except I get the error     "Controller method [index] not found." when I don't actually call any index method since they are both named differently.
  I'm new at this so sorry if it's not clear.</p>
  
  <p>UPDATE:
  Like I said in the commentaries, I found out combining the route into a route::controller got rid of my previous problem but unfortunately I'm still unable to get the ajax to send data to my controller. I get no errors, but the ajax doesn't load anything to the controller. Any idea what might be wrong with my ajax?:</p>
  
  <pre><code>$(document).ready(function() {
      $('form#find').submit(function() {
          $.ajax({
              url : '{{URL::to('/')}}',
              type: "POST",
              dataType: 'json',
              data: { search: $('.search-query').val() },
              success: function(info){
                   console.log(info);
              }
          });
          return false;
      });
  }); 
  </code></pre>