[英]I am trying get price of specific product using ajax call. so far i had tried this. but i am not getting the price after selecting product
my blade.php我的blade.php
<select name="productname[]" class="form-control productname">
<option value="0" selected="true" disabled="true">Select Product</option>
@foreach ($stock as $product)
<option value="{{$product->id}}">{{$product->productname}}</option>
@endforeach
</select>
user select product from here and i want ptice input feild auto-filled.用户从这里选择产品,我想要自动填充 ptice 输入字段。
<td><input type="text" name="price[]" class="form-control price"></td>
using this javascript使用这个 javascript
$('tbody').delegate('.productname','change', function(){
var tr=$(this).parent().parent();
var id = tr.find('.productname').val();
var dataId={'id':id};
$.ajax({
type : 'GET',
url : "{{route('findprice')}}",
dataType: 'json',
data : dataId,
success:function(data){
tr.find('text.price').val(data[0].price);
}
});
});
and in my controller I am using this thing.在我的控制器中我正在使用这个东西。
public function findprice(Request $request)
{
$data = Stock::where('price')->where('id',$request->id)->first();
return response()->json($data);
}
anyone who can help me out.任何可以帮助我的人。
You have a mistake in query.你有一个查询错误。 Add this
添加这个
$data = Stock::select('price')
->where('id',$request->id)
->first();
You placed 'where' instead of 'select'您放置了“where”而不是“select”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.