如何在laravel视图中打印json响应数组?

时间:2017-10-13 09:12:20

标签: php json ajax laravel-5.4

Ajax请求:

<script type="text/javascript">
$(document).ready(function() {
  $(document).on('click', '.nonliveValues', function() {
    $.ajax({
      url :"{{url('getNonLiveValues')}}"  ,
      type: 'GET',
      dataType:"json",
      success: function (data)
      {
        //alert(data);
        $("#qcverifiedCount").html(data.verifiedCount);
        //alert(data.SKUID);
        $.each(data.verifiedValues,function(index,value){
             alert(value.SKUID);
        });
      },
    });
  });
});
</script>

这是我从数据库获取值的ajax请求,需要在视图中显示它。

控制器:

public function getNonLiveValues()
{
  $verifiedValues= priceInfo::join('productDescription', 'productDescription.productId', '=', 'productPriceDetails.productId')
   ->join('productAdditionalInformation', 'productAdditionalInformation.productId', '=', 'productPriceDetails.productId')
   ->join('products_photos', 'products_photos.productId', '=', 'productAdditionalInformation.productId')->select('products_photos.filename','productPriceDetails.SKUID','productDescription.modelName','productPriceDetails.productName','productPriceDetails.stock','productPriceDetails.sellingPrice','productPriceDetails.nationalDelCharge')
        ->where('productPriceDetails.nonliveStatus', '=', "QCVerified")
      ->Where('productAdditionalInformation.nonliveStatus','=',"QCVerified")
      ->Where('productDescription.nonliveStatus','=',"QCVerified")
      ->Where('products_photos.nonliveStatus','=',"QCVerified")
      ->where('productPriceDetails.listingStatus','=',"Active")->whereNotNull('MRP')->whereNotNull('listingStatus')->whereNotNull('fulfillmentBy')->whereNotNull('ProcurementType')->whereNotNull('procurementSLA')->whereNotNull('stock')->whereNotNull('localDelCharge')->whereNotNull('zonalDelCharge')->whereNotNull('nationalDelCharge')->whereNotNull('packWeight')->whereNotNull('packLength')->whereNotNull('packHeight')->whereNotNull('packBreadth')->whereNotNull('HSN')->whereNotNull('GST')->whereNotNull('luxuryCess')->get();

     $verifiedCount=count($verifiedValues);
     return response()->json(array('verifiedValues'=>$verifiedValues,'verifiedCount'=>$verifiedCount));

  }

这是我的laravel控制器函数,我从db返回值及其计数。

以下是返回的JSON示例:

[
  {
    "filename":"MEBFSrGg8rjB1Hao0LOb2php6XaNihWH9zZGYQTy.png",‌
     "SKUID":"SK8900",
     "mo‌​delName":"C123",
     "pro‌​ductName":"Video Door Phone",
     "stock":"6",
     "sellingPrice":"3",
     "nationalDelCharge":"3‌​"
  }
]

0 个答案:

没有答案