weixin_33725722 2017-10-24 22:11 采纳率: 0%
浏览 56

在Laravel 5.5中使用AJAX

I'm building a web application using Laravel 5.5

I created a basic user relationship system, and now I want to create a add friend button in the user profile. I don't want to wrap this inside a form just to send a friend request, so I was thinking to make a simple AJAX post request to the server passing the logged user id and the target user id:

$.post("/request/path", { "user_1": [...] }, function () {...});

However I'm new to Laravel (and routing in general) therefore I'm not sure if I should define a route in the api.php route file and make the request to, for example, /api/friend-request, or define a route in web.php like I did for login/register post requests. What's the proper way?

  • 写回答

2条回答 默认 最新

  • weixin_33726313 2017-10-24 23:11
    关注

    If you are doing it with an AJAX call on the views, in my opinion you should do it at web.php. But it should be inside of a route group as named Ajax. You can check out Laravel Documentation for route groups.

    评论

报告相同问题?