简体   繁体   English

AJAX返回在Laravel中找不到404

[英]AJAX returning 404 Not Found in Laravel

This is my route and I want to post the data through ajax but it gives me the 404 not found error 这是我的路线,我想通过ajax发布数据,但这给了我404 not found错误

Route::post('{req_id}/com/{id}','CompanyController@store');

This is my Ajax code in view 这是我的Ajax代码

 $('#body_tb tr td a').click(function () {

        var id = $(this).attr('id');
        var req_id = {{$req_id}}

        $.ajax({

            type:"POST",
            url :req_id+"/com/"+id,

            data :{
                _token: "{{csrf_token()}}",
                company_id : id,
                req : req_id
            },
            success: function(data) {

            }

        });

    });

This is Controller 这是管制员

 public function store($id)
{

    print_r($_POST);
    exit();

Change your method in the controller: 在控制器中更改您的方法:

public function store($req_id, $id)
{
    print_r($_POST);
    exit();
}

The method needs all of the parameters of the route in order. 该方法按顺序需要路径的所有参数。 $req_id is missing in yours. 您缺少$req_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM