$('#sever_id').change(function () {//第一个select
$.ajax({
'url': 'utility.php?module=server_unlock&mode=sever_list',
'type': 'post',
'data': {
sid: $(this).val()
},
'dataType': 'json',
success: function (data) {
$("#iplist_id").empty();//第二个select
$("#iplist_id").prepend("<option value='-1'>请选择</option>");//添加第一个option值
if(data.rows !== null){
for (var i = 0; i<data.rows.length; i++) {
$("#iplist_id").append("<option value="+data.rows[i].ipid+">"+data.rows[i].alias+"</option>");
}
}
},
error: function () {
}
})
});
【PHP--后台】
$sql = "SELECT sid,ipid,alias FROM iplist where sid='" . $_POST['sid'] . "' ";
$query = $pdo->query($sql);
$queryData = $query->fetchAll();
foreach ($queryData as $res) {
$data['rows'][] = array(
'ipid' => $res['ipid'],
'alias' => $res['alias'],
'sid' => $res['sid'],
);
}
exit(json_encode(['code' => 1, 'msg' => 'success', 'rows' => $data['rows']]));
网友评论