Thomas Marck Thomas Marck - 3 months ago 45
Ajax Question

Routing to pass parameters Laravel 5.3 and AJAX

I have to pass parameters per post with ajax but not working on the console I get this:

POST http://localhost:8000/prueba2 405 (Method Not Allowed)

This is my routing:

Route::get('prueba2', 'HomeController@index');

This is my ajax:

url: '{{url('prueba2')}}',
type: 'POST', // Send post data
data: 'type=fetch',
async: false,
success: function(s){
json_events = s;

This is my controller:

public function index(){

return 'hola';

All this is a test and is not the final driver nor the final ajax, but it seems to be some response by the controller. But unfortunately I get a 405.

If someone can help me with this serious problem it would be a lot of help


You are receiving a MethodNotAllowedException because you defined a GET route with Route::get('prueba2', 'HomeController@index');, but you do a POST request.

Change your AJAX type to GET or use Route::post().

The last one would look like:

Route::post('prueba2', 'HomeController@index');