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 byLaravelbecause request methodGETis not allowed to handle the route registered forPOST.First of all, I'm not familiar with
Parsleybut after observing your code, what I've found is that, you have setup theparsleyto sendAJAXrequest usingPOSTmethod but the data type is set tojsonp.In this case,
jsonpis not possible usingPOSTmethod because it sends aGETrequest (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, theParselyis sending aGETrequest instead ofPOSTrequest because ofdataType:jsonp.So, you can check the
network tabin your browser inspector to find out the request method that is being sent and you should either register the route withRoute::get()or change thedataTypeto something else, could bejsonbut you should check theParselydocumentation for available data types.