Php 向Laravel控制器发送post AJAX请求时出现404 Not Found错误

Php 向Laravel控制器发送post AJAX请求时出现404 Not Found错误,php,jquery,ajax,laravel-5,Php,Jquery,Ajax,Laravel 5,我试图通过ajax post调用将dta从视图发送到Laravel控制器。它给我错误404未发现我检查了很多东西,但我找不到错误 class AttemptController extends Controller { public function postSavegame(Request $request) { $data = $request->all(); print_r($data); //insert data to d

我试图通过ajax post调用将dta从视图发送到Laravel控制器。它给我错误404未发现我检查了很多东西,但我找不到错误

class AttemptController extends Controller {
     public function postSavegame(Request $request) {
        $data = $request->all();
        print_r($data);
        //insert data to db
        $id = $this->model->insertRow($data, $request->input($data));

        // Insert logs into database
        if ($id != '') {
             \SiteHelpers::auditTrail($request, 'New Data with ID ' . $id . ' Has been Inserted !');
            echo('Done');
        } 
    }
}
以下是视图中的AJax:

$.ajax({
            method: 'POST',
            url: "{{ URL::to('Attempt/savegame') }}",
            data: {
                quiz_id: localStorage.quiz_id,
                user_id: "{{Session::get('uid')}}",
                total_score: localStorage.achivePoints, // a JSON object to send back
                success: function (response) { // What to do if we succeed
                    console.log(response);
                },
                error: function (jqXHR, textStatus, errorThrown) { // What to do if we fail
                    console.log(JSON.stringify(jqXHR));
                    console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                }
            },
        });
这是我的路线入口

Route::post("gamesave", "AttemptController@gamesave");

在你的路由器中,你应该有-

// you should write exactly the same name defined in controller
Route::post("/gameSave", "AttemptController@postSavegame");
在阿贾克斯-

// you have to use exaclty same url specified in router  
url :   "{{ URL::to('/gameSave') }}", 

在ajax中有
savegame
,在路由中有
gameSave
。它的作用不是,我的意思是,在ajax调用中,您有一部分URL作为
savegame
,但是路由有
gameSave
。它找不到路线,因为它们不一样。请让我知道。。。不管它对你有用与否。。如果有帮助,请接受正确答案并投票