2017-06-17 13 views
0
ウェブURLのchnangeと

AjaxのURLの変更私のAjaxコードLaravel 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 

コードであればサイトのURLが変更された場合は

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

エラーが

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

答えて

1

を発生し、以下のようなとしてあなたのルートを変更してください:

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

をあなたはすべてのURLがルート –

+0

はい、Uは、すべてのURLのルートを定義する必要がありますを意味します。 urlがmissongなら404(Not Found)エラーが出ます – Muthu17