title: Laravel registration via ajax
body: <p>I'm trying to make user <code>registration</code> process via <code>ajax</code> in <code>laravel</code>. But I'm unable to do that.</p>
  
  <p>Routes</p>
  
  <pre><code>Route::get('/register', 'Auth\AuthController@getRegister')-&gt;name('register');
  Route::post('/register', 'Auth\AuthController@postRegister')-&gt;name('postRegister');
  </code></pre>
  
  <p>HTML form</p>
  
  <pre><code>&lt;form action="{{ route('postRegister') }}" method="POST" id="registerForm"&gt;
      &lt;h4&gt;REGISTER NOW&lt;/h4&gt;
      &lt;hr&gt;&lt;br&gt;
      &lt;input type="text" name="name" class="form-control" placeholder="Name"&gt;
      &lt;br&gt;
      &lt;input type="number" name="student_id" class="form-control" placeholder="Student ID"&gt;
      &lt;br&gt;
      &lt;input type="email" name="email" class="form-control" placeholder="Email address"&gt;
      &lt;br&gt;
      &lt;input type="number" name="phone" class="form-control" placeholder="Phone no"&gt;
      &lt;br&gt;
      &lt;input type="password" name="password" id="password" class="form-control" placeholder="Choose password"&gt;
      &lt;br&gt;
      &lt;input type="password" name="password_confirmation" class="form-control" placeholder="Confirm password"&gt;
      &lt;br&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-12 text-right"&gt;
              &lt;button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="registerButton"&gt;&lt;span id="regLoader" style="display: none"&gt;&lt;i class="fa fa-spinner fa-pulse"&gt;&lt;/i&gt;&lt;span class="sr-only"&gt;Loading...&lt;/span&gt;&amp;nbsp;&lt;/span&gt;
              Register&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      {{ csrf_field() }}
  &lt;/form&gt;
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$('#registerForm').submit(function(e){
      e.preventDefault();
  
      $.ajax({
          type: 'POST',
          url: '/register',
          data: $(this).serialize(),
          dataType: 'json',
  
          success: function(data){
  
          },
          error: function(data){
  
          }
      });
  });
  </code></pre>