【发布时间】:2017-10-14 03:26:46
【问题描述】:
我正在尝试将动态数据传递给引导模式。我想要做的是通过使用 jQuery 发布请求传递数据 ID。我的观点 users 包含用户列表。当我点击 details 按钮时,我想使用 jquery post 传递 id,然后使用 eloquent,检索每个用户的所有信息。
我的看法
<table class="table">
<thead class="thead-default">
<tr>
<th>No.</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php use App\User;
$users = \App\User::where('admin',0)->get();
$i = 1;?>
@foreach($users as $user)
<tr id="{{$user->id}}">
<th scope="row">{{$i}}</th>
<td width="65%">{{ucfirst($user->name)." ".ucfirst($user->surname)}}</td>
<td>
<button class="btn btn-info infoU"
data-toggle="modal"
data-target="#viewUser"
data-id="{{$user->id}}">
<span class="glyphicon glyphicon-file"></span>
Details</button>
</td>
</tr>
<?php $i++ ?>
@endforeach
</tbody>
</table>
我的脚本
$(document).ready(function () {
$(".infoU").click(function (e) {
$('#pic').attr('src',$(this).attr("data-pic"));
$currID = $(this).attr("data-id");
$.post("detail.blade.php", {id: $currID}, function (data) {
$('#user-data').html(data);
}
);
});
});
我的模态
<div class="modal fade" id="viewUser" role="dialog">
<div class="modal-dialog" style="min-height: 800px">
<div class="modal-content">
<form method="get" action="">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="modal-title" style="color: #BC0E91">User Details</h2>
</div>
<div class="modal-body">
<div id="user-data">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
detail.blade.php
<?php
if ($_REQUEST['id']){
$id = $_REQUEST['id'];
echo $id;
}
$usr = \App\User::where('id', $id)->first();
?>
我不知道为什么这不起作用,我不确定是否可以在脚本中传递路由而不是 detail.blade.php。任何帮助深表感谢。谢谢
【问题讨论】:
-
你需要 paas 路由而不是刀片文件的名称
-
我已经尝试过了,但我似乎无法让它工作
-
能否请您也发布您的路由文件和控制器方法?
-
@YasenSlavov 我在下面发布了它们。谢谢
标签: jquery laravel bootstrap-modal