$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
的数据?
答案 0 :(得分:1)
尝试这个
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);
}