路由传递参数Laravel 5.3和AJAX

Routing to pass parameters Laravel 5.3 and AJAX

我必须使用 ajax 按 post 传递参数,但无法在控制台上工作,我得到这个:

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

这是我的路线:

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

这是我的 ajax:

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

这是我的控制器:

public function index(){

    return 'hola';
}

这一切都是测试,不是最终的驱动程序,也不是最终的ajax,但它似乎是控制器的一些响应。但不幸的是我得到了 405.
如果有人能帮我解决这个严重的问题,那将是很大的帮助

您收到 MethodNotAllowedException,因为您使用 Route::get('prueba2', 'HomeController@index'); 定义了 GET 路由 ,但您执行了 POST 请求

将您的 AJAX 类型更改为 GET 或使用 Route::post()

最后一个看起来像:

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