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.

    评论

报告相同问题?

悬赏问题

  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页