js代码
<script type="text/javascript">
function get_next(t,pid){ //当前元素的id,当前option的value,一般都是id吧?反正我的是
$.ajax({
type: "POST",
url: "/index.php?type=company&m=action&a=getNext",
data: "pid="+pid,
dataType: ‘json‘,
success: function(msg){
$("#"+t).next(‘select‘).html(msg.str);//拼接html
}
});
}
</script>
php代码
public function getNext()
{
$next = $sql //查找数据库pid=post过来的id的sql
$str = "<option value=‘‘>请选择</option>";
foreach ($next as $val) {
$str .= "<option value=‘".$val[‘id‘]."‘>".$val["name"]."</option>";
}
$msg["str"] = $str;
echo json_encode($msg);
die();
}
可以在任何地方调用,但是还是有个小缺陷,我选择无视。嘻嘻