$query = "SELECT Item_Name from item_details";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$optionValue[] = "<option value='" . $row['Item_Name'] . "'>" . $row['Item_Name'] . "</option>";
}
$query1 = "SELECT Item_Name from item_addon";
$result1 = mysql_query($query1);
while ($row = mysql_fetch_array($result1)) {
$optionValue1[] = "<option value='" . $row['Item_Name'] . "'>" . $row['Item_Name'] . "</option>";
}
return json_encode(array("a" => $optionValue, "b" => $optionValue1));
我需要分析
a
和b
的数据optionDetails = $.parseJSON(data);
for (i = 0; i < optionDetails.length; i++) {
det_item_name = optionDetails[i];
$('#det_item_name').append(det_item_name);
}
optionAdd = $.parseJSON(data)
for (i = 0; i < optionAdd.length; i++) {
det_item_name = optionAdd[i];
$('#add_name').append(add_name);
}
如何解析
a
和b
中的optionDetails
和optionAdd
数据? 最佳答案
试试这个
var json_array = $.parseJSON(data);
var optionDetails = json_array.a;
for (i = 0; i < optionDetails.length; i++) {
det_item_name = optionDetails[i];
$('#det_item_name').append(det_item_name);
}
var optionAdd = json_array.b;
for (i = 0; i < optionAdd.length; i++) {
det_item_name = optionAdd[i];
$('#add_name').append(add_name);
}