Reputation: 117
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)
Upvotes: 0
Views: 38
Reputation: 1541
Please change your route as like below:
Route::post('surveys/{id}/ajax',function (){
auth()->user()->unreadNotifications()->update(['read_at' => \Carbon\Carbon::now()]);
})->name('ajax');
Upvotes: 1