您好,我有問題顯示從數據庫中提取的JSON數據的特定值,我只想顯示產品名稱上的輸入文本如何做到這一點?我嘗試過,但它說沒有價值。如何從數據庫中提取的json數據獲取特定值?
這裏是我的JSON代碼: -
{"brcode":[{"id":"1","name":"Rolex Watch","description":"Rolex wrist watches","uom":"1000","brand":"1051","tax_id":"1","purchase_price":"5000","sale_price":"6000","barcode":"ROLEX5000","created_date":"2017-05-29 13:31:24","created_by":"1","updated_date":"2017-05-29 13:31:24","updated_by":"1","status":null},{"id":"3","name":"motorola X play","description":"Moto X play mobile phone","uom":"50","brand":"7845","tax_id":"1","purchase_price":"20000","sale_price":"25000","barcode":"MOTOXPLAY500","created_date":"2017-05-29 14:18:43","created_by":"0","updated_date":"2017-05-29 14:18:43","updated_by":"0","status":null},{"id":"4","name":" LG Smart LED TV","description":"Smart LED TV from LG","uom":"5","brand":"5420","tax_id":"1","purchase_price":"80000","sale_price":"100000","barcode":"LGSMART5012","created_date":"2017-05-29 15:39:35","created_by":"0","updated_date":"2017-05-29 15:39:35","updated_by":"0","status":null},{"id":"5","name":"Computer Intel","description":"Intel smart computer","uom":"1","brand":"1","tax_id":"1","purchase_price":"40000","sale_price":"50000","barcode":"INTELPC2123","created_date":"2017-05-29 17:59:31","created_by":"0","updated_date":"2017-05-29 17:59:31","updated_by":"0","status":null},{"id":"6","name":"DDR4 Ram","description":"Ram for computer","uom":"6","brand":"1","tax_id":"1","purchase_price":"4000","sale_price":"5000","barcode":"RAMDDR4","created_date":"2017-05-29 18:15:17","created_by":"0","updated_date":"2017-05-29 18:15:17","updated_by":"0","status":null}]}
這裏是我的功能: -
function get_barcodes() {
$.ajax({
url: 'http://localhost/retail/main/ajax_barcodes/',
type: 'POST',
datatype: 'json',
data: { 'barcode': $('#brcode option:selected').val() },
success: function (data) {
// var brcodes = JSON.parse(data);
//console.log(brcodes);
//var brCodes = JSON.parse(data);
//var json = JSON.parse(data);
//console.log(brCodes.brcode);
//$("#product_items_opts").val(barcodes.brcode.name);
// console.log(json);
console.log(data);
}
});
// $('#prdct_barcode[' + product_barcode_counter + ']').each(function(){
// $('#prdct_barcode[' + product_barcode_counter + ']').change(function(){
// });
// });
}
請忽略我寫只是爲了檢查值的評論部分。請告訴我如何從JSON數據顯示產品名稱?
是否想獲取所有產品名稱並將其顯示在某個地方? – JSONGagnon
是的,我也想顯示選擇菜單的選項中的所有條形碼,我想追加所有的條形碼選項。 –