0
我通過ajax加載的json編碼信息存在問題。我將多JSON傳遞給ajax以顯示字段值。我們如何在Ajax中編碼多JSON數據響應
如何從json中使用查詢ajax獲取字段值。
Ajax代碼:
....success:function(data){
var TotalBuyPrice = 0;
var TotalItem = 0;
$.each(data, function(c,cart){
//Condition follow 1
var InStockQty =cart.products_qty;
alert(InStockQty);
//And also follow 2
var name =cart["withoutdiscount"][0]["products_name"];
alert(name);
});
}...
PHP代碼:
這些是使用陣列以下對JSON response.By我的步驟中收集的結果
$response = array();
$response['withoutdiscount'] = $withoutdiscount;
$response['withdiscount'] = $withdiscount;
echo $_GET['jsoncallback'] . '(' . json_encode($response). ');';
jsoncallback:
({"withoutdiscount":[{"products_id":"1","products_name":"Lumia"}],
"withdiscount":[{"products_id":"2","discount_qty":"8"},
{"products_id":"3","discount_qty":"1"}
]
});