i tryed to remote validate the email and username for a registration form with parsley. I get allways the message:
public/checkUserName?username=tester 405 (Method Not Allowed)
So here is my code:
Input:
<input data-parsley-remote="{{ route('checkUserName') }}" data-parsley-remote-message="Der Username ist bereits vergeben!" data-parsley-remote-options='{ "type": "POST", "dataType": "jsonp", "data": {_token: CSRF_TOKEN, "UserName": "username" } }'
Route:
Route::post('/checkUserName', [
'uses' => 'UserController@checkUserName',
'as' => 'checkUserName'
]);
UserController:
public function checkUserName(Request $request)
{
if(user::where('UserName','=',$request->input('UserName'))->exists()){
return response::json('exists', 404);
}else{
return response::json('not exists', 200);
}
}
The error
405 (Method Not Allowed)
is thrown byLaravel
because request methodGET
is not allowed to handle the route registered forPOST
.First of all, I'm not familiar with
Parsley
but after observing your code, what I've found is that, you have setup theparsley
to sendAJAX
request usingPOST
method but the data type is set tojsonp
.In this case,
jsonp
is not possible usingPOST
method because it sends aGET
request (using a script tag...) and hence, your route is not found because you've registered the route asPOST
.So, it's happening because of inappropriate data type (
jsonp
) with the request methodPOST
. I'm sure that, theParsely
is sending aGET
request instead ofPOST
request because ofdataType:jsonp
.So, you can check the
network tab
in your browser inspector to find out the request method that is being sent and you should either register the route withRoute::get()
or change thedataType
to something else, could bejson
but you should check theParsely
documentation for available data types.