简体   繁体   English

我正在尝试使用 ajax 调用获取特定产品的价格。 到目前为止,我已经尝试过这个。 但我在选择产品后没有得到价格

[英]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.

相关问题 如何从 WooCommerce 获得产品价格,以便我可以将其与 javascript 一起使用? - How can I get the product price from WooCommerce so i can use it with javascript? 我正在尝试在 nodejs 中使用来自 DB 的搜索产品,但产品没有得到? - I am trying to use search product from DB, in nodejs but the product is not getting? 我试图根据距离查找特定路线的价格,但是每当我放置地点时,if循环返回else而不是价格 - Am trying to find price of a particular route basing on the distance but whenever i put the places, the if loop returns the else not the price 我正在尝试创建一个带有复选框的价格计算器,如果超过一定数量,它将自动折扣价格 - I am trying to create a price calculator with checkbox's that will automatically discount the price if over a certain amount 从选择框中选择产品时如何获取相关产品的价格? - How to get price of related product when I select product from a selectbox? 我正在尝试实现产品的添加和删除,但出现此错误:Uncaught TypeError: props.handleFavouriteClick is not a function - I am trying to implement the addition and removal of the product but I get this error:Uncaught TypeError: props.handleFavouriteClick is not a function 我正在尝试将我的产品列表的数量限制为10 - I am trying to limit the number of my product list to 10 Ajax / Woocommerce - JavaScript - 如何获得具有产品ID的产品价格 - Ajax/Woocommerce - JavaScript - How to get product price having product ID 我使用$ scope。$ apply在http调用后更新对象数组。 谁能告诉我正确的做法? - I am using $scope.$apply to update an array of objects after an http call. Can anyone tell me the correct way of doing it? 我正在尝试为将要构建的产品选择框架,到目前为止,我倾向于Nagare ...有什么想法吗? - I'm trying to pick a framework for a product I'm about to build, and so far I'm leaning toward Nagare… Any thoughts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM