I am having a problem with Laravel.
I try to do a POST with JQuery to my Controller, but when I do that, I recieve a HTTP 302 code (found), and after that It creates a GET to the same controller URL.
Here there is my code:
WizardController.php
class WizardController extends Controller
{
public function saveForm(Request $request) {
$data = $request->data;
error_log(print_r($data, true));
return response()->json(['message' => 'test']);
}
}
routes/web.php
Route::group(['prefix' => 'wizard', 'middleware' => 'auth'], function(){
Route::post('create', 'WizardController@saveForm');
})
Wizard.html
<script>
var token = $('meta[name=csrf-token]').attr('content');
$.ajax('wizard/create', function() {
method: 'POST',
data: {'data' : 'test'},
headers: { 'X-CSRF-TOKEN': token },
success: function(data) {
console.log(data);
}
});
</script>
I even cannot see the log in my controller. Any suggestion?
Thanks