【发布时间】:2021-04-23 05:18:50
【问题描述】:
I want show the specific record by id through on click event in model
模型正在打印,但 url 函数没有获取任何详细信息
<button id="{{$res->id}}" class="btn btn-info" data-toggle="modal" data-target="#modal-xl" onclick="viewslip(this.id)">View Slip</button>
我没有收到任何错误,所以我可以调试它。
在这里,我使用 ajx 请求通过 id 通过 onclick 函数获取数据
函数 viewlip(id){
$.ajax({
url: "{{url('/view/payment/slip')}}"/+id,
type: "GET",
dataType:"json",
success:function(data){
$('#fname').text(data.paymentslip.firstname);
$('#lname').text(data.paymentslip.lastname);
}
})
}
model where I am appending data
<div class="table-responsive">
<table class="table">
<tr>
<th style="width:50%">First Name:</th>
<td><h1 id="fname"></h1></td>
</tr>
<tr>
<th style="width:50%">last Name:</th>
<td><h1 id="lname"></h1></td>
</tr>
<tr>
Method in Controller
public function viewslip($id){
$paymentslip= Order::where('reservationid', '=', $id)->firstOrFail();
return response::json(array(
'paymentslip'=>$paymentslip,
));
}
【问题讨论】:
-
那么什么不起作用?
-
感谢斯瓦蒂对帮助我的兴趣。实际上控制台中没有显示错误,我没有在 html 表中打印任何结果
-
首先检查
console.log(data)是否存在? -
你好诺曼。实际上我认为我的 onclick 函数没有执行。这就是为什么我没有在 Console .log(数据)中获取任何数据。如何检查带有按钮的 onclick 函数是否正常工作