As mentioned in the subject I'm getting a MethodNotAllowedHttpException in RouteCollection.php when trying to submit a form using jQuery and ajax
I've tried the following in my routes.php file
Route::post('/send/', 'CommsController@send');
and
Route::patch('/send/', 'CommsController@send');
Controller
use App\Http\Controllers\Controller;
class CommsController extends Controller
{
protected function send(Request $request);
{
return response($request);
}
}
jQuery ajax
if ( isValid ) {
$( ".validation-summary" ).html( "Sending message..." );
var data = "";
data = "message_type=contact"
+ "&first_name=" + first_name.val()
+ "&last_name=" + last_name.val()
+ "&email=" + email.val()
+ "&message=" + message.val()
$.ajax({
type: "post",
url: "send",
data: data,
error: function( response ) {
$( ".validation-summary" ).removeClass( "success" );
$( ".validation-summary" ).addClass( "validation-summary error" );
$( ".validation-summary" ).html( "Error" );
},
success: function() {
$( ".validation-summary" ).html( "Message sent." );
}
});
return false;
} else {
return false;
}
Thanks.