ajax - Laravel:使用 Ajax 和 Jquery 从选择选项中获取值
问题描述
我对我的代码有疑问,我有模块,管理员可以过滤用户订购的内容。场景管理员有/有一个订购的客户列表,管理员将选择哪个客户前。客户 2所以现在 url http://localhost:8000/customer_all_orders/2 注意:/2 是 customer_id 有 4 个订单的记录,
所以现在管理员可以过滤记录,如果管理员选择下拉3个订单查询将限制3个,也可以限制15个订单等。
- 3 个订单
- 15 个订单
- 显示所有订单
问题:如果我在选择选项上选择了一些值,为什么订单不能限制订单?但状态码是(OK)
我的脚本/控制器:
public function customer_all_orders($id,Request $request) {
$filter = $request->get('filter');
if(isset($filter))
{
$customer_details_id = DB::select('SELECT * FROM customer_details WHERE customer_id = ? ',[$id]);
$select_order_properties = DB::select('SELECT * FROM order_properties WHERE customer_id = ? ORDER BY order_id DESC LIMIT '.$filter.' ',[$id]);
$select_order_details = DB::select('SELECT order_properties_id,menu_cat_image,or_number,Quantity,Subtotal,menu_cat_name FROM order_properties as op LEFT JOIN (SELECT order_properties_id,product_id,UnitPrice,Quantity,(UnitPrice * Quantity) as Subtotal FROM order_details_properties) odp ON op.order_id = odp.order_properties_id
LEFT JOIN (SELECT menu_cat_image,menu_cat_name,menu_cat_id FROM menu_category) mc ON odp.product_id = mc.menu_cat_id
WHERE customer_id = ? ',[
$id
]);
return View('customer_all_orders')
->with('customer_details',$customer_details_id)
->with('order_properties',$select_order_properties)
->with('customer_order',$select_order_details);
}
else
{
$customer_details_id = DB::select('SELECT * FROM customer_details WHERE customer_id = ? ',[$id]);
$select_order_properties = DB::select('SELECT * FROM order_properties WHERE customer_id = ? ORDER BY order_id DESC LIMIT 4',[$id]);
$select_order_details = DB::select('SELECT order_properties_id,menu_cat_image,or_number,Quantity,Subtotal,menu_cat_name FROM order_properties as op LEFT JOIN (SELECT order_properties_id,product_id,UnitPrice,Quantity,(UnitPrice * Quantity) as Subtotal FROM order_details_properties) odp ON op.order_id = odp.order_properties_id
LEFT JOIN (SELECT menu_cat_image,menu_cat_name,menu_cat_id FROM menu_category) mc ON odp.product_id = mc.menu_cat_id
WHERE customer_id = ? ',[
$id
]);
return View('customer_all_orders')
->with('customer_details',$customer_details_id)
->with('order_properties',$select_order_properties)
->with('customer_order',$select_order_details);
}
}
我的 Ajax 请求:
$(document).ready(function(){
$('#filter_orders').on('change',function(){
var value = this.value;
var customer_id = $(this).find(':selected').attr('data-user-id');
$.ajax({
url:'/customer_all_orders/' + customer_id,
type:'get',
data:{filter:value},
success:function(response){
console.log(response);
},
error: function(error){
console.log(error);
}
})
});
})
我的HTML:
<select class="form-control" id="filter_orders" data-user-id='{{$details->customer_id}}'>
<option value="" selected="">Select Filter Orders</option>
<option value="3" data-user-id='{{$details->customer_id}}'>Last 3 Orders</option>
<option value="15" data-user-id='{{$details->customer_id}}'>Last 15 Orders</option>
<option value="*" data-user-id='{{$details->customer_id}}'>Show all Orders</option>
</select>
解决方案
推荐阅读
- c++ - C++ 计时器,Windows 窗体,单击按钮开始
- r - 将 rhandsontable 保存到 .Rda
- android - 错误:解密字符串 Java 时出现错误的 base-64
- sql-server - SQL Server 2008 升级 - 计算计数
- c++ - 使用 opencv2 和 c++ 将帧写入 MP4 格式
- python - Pygame pop() 类崩溃
- javascript - 检查数组是否包含另一个数组JS
- sql - PLS-00103 遇到符号“END”
- javascript - 我正在尝试通过添加和删除我已经设置样式但它不起作用的活动类来创建切换按钮
- python - 使用日期时间列 Pandas 将 CSV 文件读取到 MySQL