weixin_33711641 2015-07-03 09:09 采纳率: 0%
浏览 3

laravel 5 ajax请求

i had a user list form in laravel. so i want when i click the table row, it automatically load the user details from database without redirecting. i've heard about ajax. but i have no idea how to use it in laravel..

i want to make like this enter image description here

enter image description here

but without redirecting page..

$("tr").click(function() 
    {
        $.ajax({
          type: "GET",
          url: $(this).data("href"),
          dataType: "text",
          success : function(data) {
                      $('#details-container').load(data)
                    }
        });
    });

does it supposed to be like this? but how did i get the data from database? i have no idea. please help me..

  • 写回答

2条回答 默认 最新

  • weixin_33712881 2015-07-03 09:20
    关注

    Its the same in Laravel as in "native" PHP. With your Ajax request your are able to send and asynchronous request, and refresh just a little part of your website, so you dont need to reload your whole page.

    If you want to make it work with laravel, you should:

    1. create a route for your requests

      Route::get('user/{id}', function($id)
      {
          // So all your GET requests with any user id goes to this script (in routes.php) 
      
          // here you should load your user information, maybe with ORM
      
          $user = User::where('id','=',$id)->get();
      
         // Build any HTML snippet, or build JSON data (and build the information in Javascript on your page)
      
       //return here JSON / or html
       $data = array() -> containts information for the blade template
       return view('users.information', $data);
      
      });
      
    2. Your AJAX request returns now JSON / or HTML, append it to your site where you would like to show it.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器