简体   繁体   中英

How to use laravel route in ajax url

This route marks notifications as read, using ajax

Route::get('markAsRead', function() {
    Auth::user()->unreadNotifications->markAsRead();
    return Redirect()->back();
});

function markNotificationAsRead()
{
    $.get('markAsRead');
}

This works from the root directory:

http://localhost/markAsRead

but when i want to access this route from

http://localhost/user/markAsRead 

it does not work, so how Can I use the laravel route and make it work?

Without beginning slashes, the URL is relative to the current page. To make it absolute, you want to add a slash before it:

function markNotificationAsRead()
{
    $.get('/markAsRead');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM