HTML:
<select multiple size="10" class="show" id="boxA"></select>
<nav id="buttons">
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li><a class="remove" href="#">Remove</a></li>
<li><a class="add" href="#">Add</a></li>
</ul>
</nav>
<select multiple size="10" class="show" id="boxB"> </select>
如何将<select multiple size="10" class="show" id="boxB"> </select>
转换为JSON数组,以便我可以通过ajax将其发送到服务器?
为您的信息选择框,其中包含由<optgroup>.
PHP文件:
$last_category = "";
while ($row = mysqli_fetch_array($result)) {
$levels = $row['level_name'];
$levels_id = $row['level_id'];
$subjects = $row['subject_name'];
$subjects_id = $row['subject_id'];
if ($last_category != $levels) {
$last_category = $levels;
echo '<optgroup label="' . $levels . '" class="' . $q .'">';
}
echo '<option value="' . $subjects_id . '">' . $subjects . '</option>';
if ($last_category != $levels)
echo '</optgroup>';
}
答案 0 :(得分:0)
您可以这样做:
var json = $(':input').serializeArray()
var string = JSON.stringify(json)