I have this JSON response from the query from the database:
[{
"IMAGE": "",
"NAME": "BEANS,LIMA,DRY",
"NSN": " 8915005302173",
"FIIG": "T113-J",
"INC": "2153",
"CRITICALY": "0",
"TYPE_II": "4",
"DEMIL": "a",
"DATE": "2003-06-12",
"ESD": ")",
"PMIC": "a",
"ADPEC": "0",
"HMIC": "n",
"HCC": "",
"ENAC": "",
"SUPPLIER": "Defense Supply Agenc",
"CAGE": "54027",
"PART_NUMBER": "0",
"STAT": "a",
"RNCC": "3",
"RNVC": "1",
"DAC": "4",
"RNAAC": "zz",
"SADC": "",
"MSDS": "",
"MOE": "ds",
"USC": "i",
"AAC": "h",
"SOS": "sms",
"UI": "lb",
"UNIT_PRICE": "1",
"QUP": "1",
"CIIC": "u",
"SLC": "0",
"MGT_CTRL": "",
"REP": "",
"SUPPLY_PACKAGE_TYPE": "Fruits and Vegetables",
"SPECIAL_FEATURES": "",
"DEFINITION": "Note-Subsistance items which are specifically prepared for dietetic use are classified in Class 8940. Nondietetic foods, even though they bear the same approved item names as corresponding dietetic fo"
}]
I want to select just the NSN number. This is the Ajax call:
$(document).ready(function(){
function show(){
$.ajax({
url:"getProducts",
success:function(data){
var d=data;
$("#output").html(d);
}
});
}
show();
});
Tell the $.ajax() method to treat your returned data as JSON by adding dataType :'json'. As your data will then be an object that has an array, which has an object at the first index, you will access your properties with data[0].PROPERTY. Example:
$.ajax({
url:"getProducts",
dataType: 'json',
success:function(data){
var d=data[0];
$("#output").html(d.NSN);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With