I am having trouble implementing a user registration process using ajax in the Laravel framework.
Routes
Route::get('/register', 'Auth\AuthController@getRegister')>name('register');
Route::post('/register', 'Auth\AuthController@postRegister')>name('postRegister');
HTML form
<form action="{{ route('postRegister') }}" method="POST" id="registerForm">
<h4>REGISTER NOW</h4>
<hr><br>
<input type="text" name="name" class="form-control" placeholder="Name">
<br>
<input type="number" name="student_id" class="form-control" placeholder="Student ID">
<br>
<input type="email" name="email" class="form-control" placeholder="Email address">
<br>
<input type="number" name="phone" class="form-control" placeholder="Phone number">
<br>
<input type="password" name="password" id="password" class="form-control" placeholder="Choose password">
<br>
<input type="password" name="password_confirmation" class="form-control" placeholder="Confirm password">
<br>
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect" id="registerButton"><span id="regLoader" style="display: none"><i class="fa fa-spinner fa-pulse"></i><span class="sr-only">Loading...</span> </span>
Register</button>
</div>
</div>
{{ csrf_field() }}
</form>
JS
$('#registerForm').submit(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: '/register',
data: $(this).serialize(),
dataType: 'json',
success: function(data){
},
error: function(data){
}
});
});