php - 如何通过 Ajax 检索记录并在 Laravel 表中显示
问题描述
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 函数 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,
));
}
解决方案
使用以下代码
onclick="viewslip({{$res->id}})"
在你的函数中使用
function viewslip($orderId){
var orderId = $orderId;
$.ajax({
url:"{{url('')}}/view/payment/slip/"+orderId, // Your problem was here
type: "GET",
dataType:"json",
success:function(data){
$('#fname').text(data.paymentslip.firstname);
$('#lname').text(data.paymentslip.lastname);
}
})
推荐阅读
- php - 在 WooCommerce 管理员订单列表中添加自定义订单状态以过滤菜单
- go - 使用反射检索类型别名备用名称
- ms-access - Access Vba - 如何将记录集的当前记录设置为另一个记录集
- ethereum - 现在完整的 geth 以太坊节点的大小是多少?
- angular - Angular 2 Typescript 从文件系统转换问题中检索 jpeg 图像
- r - ggplot2:使用 geom_point 增加分类轴刻度之间的空间
- java - java程序找不到符号类Node但我导入了它
- r - readr:传递一串列类
- vue.js - vue-devtools 总是被 nuxt.js 禁用
- c - 预处理器运算符“定义”的优先级?