将数据库值传递给模式弹出窗口 [英] pass the database value to modal popup

查看:70
本文介绍了将数据库值传递给模式弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将获取的数据库值传递给模式弹出窗口.我已经从数据库中获取了值,并以分页的形式列在表中.

I want to pass the fetched database value to modal popup.I have fetched values from database and listed as table with pagination.

名称"字段具有链接,并会在触发链接时显示模型弹出窗口.我想列出我从laravel 5.3中的链接检查的名称详细信息.

'name' field has link and will show model popup while triggering a link.I want to list the details of name which I check from the link in laravel 5.3.

现在所有链接的模型弹出式菜单均以模式标题3"触发.我想知道如何传递值模式弹出式窗口并显示特定ID的详细信息.我想知道是否需要单独的页面或控制器来执行此操作.在何处编写用于模式弹出窗口的查询.如何显示特定ID的详细信息.

Now model pop up trigered with 'Modal Header 3' for all link.I want to know how to pass the value modal popup and show the details of particular id. I want to know to know shall I need separate page or controller to do this.Where to write the query for modal popup.How can I display the details of specific Id.

id名称年龄

1 xx 26

2 yy 28

3 zz 30

<table border = 1>
     <tr>
        <td>ID</td>
        <td>Passanger Name</td>
        <td>Destination</td>
        <td>Created Date</td>
     </tr>
     @foreach ($users as $user)
     <tr>
        <td>{{ $user->p_id }}</td>
        <td><a href="#" class="viewPopLink" role="button" data-id="{{ $user->p_id }}" data-toggle="modal" data-target="#myModal">{{ $user->p_name }}<a></td>
        <td>{{ $user->destination }}</td>
        <td>{{ $user->created_date }}</td>
    </tr>
     @endforeach

  </table>
{{$users->links()}}

 <div class="modal fade" id="myModal" role="dialog">
 <div class="modal-dialog">

  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Modal Header {{ $user->p_id }}</h4>
    </div>
    <div class="modal-body">
      <p>Some text in the modal.</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>

</div>

推荐答案

使用jquery ajax请求并获取用户数据以设置模式

Use jquery ajax request and get user data to set modal

 $(document).on('click', '.viewPopLink', function() {    
    var user_id = $(this).data('id');
    $.ajax({
      url: 'user/get-details',
      type: 'GET',
      data: 'id='+user_id,
      dataType: 'JSON',
      success: function(data, textStatus, jqXHR){
        var name = data.name;
        $('.modal-title').html('<span>Modal Header ' + name + '</span>');   
        $('#myModal').modal('show');
      },
      error: function(jqXHR, textStatus, errorThrown){

      },
    });    
  });

控制器方法

  //Get user data
  public function getDetails(Request $request)
  {
    $request_data = $request->all();
    $user_id = $request_data['id'];
    $user_data = User::where('id', $user_id)->first();
    return response()->json($user_data);
  }

这篇关于将数据库值传递给模式弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆