Laravel Ajax 问题

Laravel Ajax issue

Ajax url随着网络的变化而变化URL我的ajax代码

 $.ajax({
                url:"ajax",
                type:"post",
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                success: function(data)
                {
                    alert(1);
                   console.log(data);
                },
                error: function(data){

                }
            })

Route.php

Route::post('ajax',function (){
            auth()->user()->unreadNotifications()->update(['read_at' => \Carbon\Carbon::now()]);
    })->name('ajax');

如果站点 URL 是

http://localhost/servay_project/surveys

代码运行 perfactly 如果 URL 站点更改

http://localhost/servay_project/surveys/55/questions

发生错误

http://localhost/servay_project/surveys/55/ajax 404 (Not Found)

请如下更改路线:

Route::post('surveys/{id}/ajax',function (){
            auth()->user()->unreadNotifications()->update(['read_at' => \Carbon\Carbon::now()]);
    })->name('ajax');