title: Laravel 5.1 save something in database with ajax call
body: <p>I am building an application where users can upload projects. I am implementing a system where users can 'Like/Unlike' other projects. I am trying to use an AJAX call to save likes. Users are able to like projects on the detail page of a project (/projects/{id})</p>
  
  <p>I have a table users, projects and likes. My plan is to save the likes in the likes table obviously so a record looks like this: id, user_id, project_id. In the future I can do a COUNT query and find out how many likes each project has, etc.</p>
  
  <p>For some reason when I click on the like button my application gets stuck and keeps loading until it crashes.</p>
  
  <p>My files:
  Ajax call</p>
  
  <pre><code>$(document).ready(function(){
          console.log("js loaded");
          $('#likeform').on('submit', function(e) {
              console.log("like submitted");
              e.preventDefault();
  
              $.ajax({
                  url: $(this).parent().attr('action'),
                  type: "post",
                  data: {'_token': token, 'user_id': $('input[name=user_id]').val(), 'project_id': $('input[name=project_id]').val()},
                  success: function(data){
                      alert(data);
                  }
              })
          });
      });
  </code></pre>
  
  <p>My Form</p>
  
  <pre><code>  {!! Form::open(array('url'=&gt;'projects/'.$project-&gt;id.'/like','method'=&gt;'POST', 'id'=&gt;'likeform')) !!}
      &lt;input type="hidden" id="token" value="{{ csrf_token() }}"&gt;
      {!! Form::Submit('Like', array('class'=&gt;'send-btn')) !!}
  {!! Form::close() !!}
  </code></pre>
  
  <p>My Routes:</p>
  
  <pre><code>Route::get('/', 'LikeController@index');
  Route::post('projects/{id}/like', 'LikeController@like');
  </code></pre>
  
  <p>My like function in the LikeController:</p>
  
  <pre><code>public function like()
  {
      if(Request::ajax()) {
          $data = Input::all();
          print_r($data);die;
      }
  }
  </code></pre>