dongmijgnnq0118 2017-06-17 12:20
浏览 16
已采纳

Laravel Ajax问题

Ajax url change with the chnange of web URL my ajax code

 $.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');

if the URL of site is

http://localhost/servay_project/surveys

the code run perfactly if the URL of site change

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

the error occur

http://localhost/servay_project/surveys/55/ajax 404 (Not Found)
  • 写回答

1条回答 默认 最新

  • duanfei1975 2017-06-17 12:23
    关注

    Please change your route as like below:

    Route::post('surveys/{id}/ajax',function (){
                auth()->user()->unreadNotifications()->update(['read_at' => \Carbon\Carbon::now()]);
        })->name('ajax');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?