html代码片段
<div class="form-group"><div class=" col-xs-12 col-sm-3 col-md-3 col-lg-3" ><label class="col-xs-12 col-sm-5 col-md-5 control-label input_lable order_style_labe" style="width: 35%;">线路</label><select name= "line_code" id="line_code" class="form-control input_content order_style_content" style="width: 65%;"><option value="">全部</option><option value="1">徐凤年</option><option value="2">陈平安</option>{/loop}</select></div><div class=" col-xs-12 col-sm-3 col-md-3 col-lg-3" ><label class="col-xs-12 col-sm-5 col-md-5 control-label input_lable order_style_labe" style="width: 35%;">班次</label><select name= "sch_code" id="sch_code" class="form-control input_content order_style_content" style="width: 65%;"><option value="">全部</option><option value="1">洛阳</option><option value="2">阮秀</option></select></div></div>
jQuery代码片段
<script>$("#line_code").change(function () {var $this = $(this);var line_code = $this.find("option:selected").val();console.log(line_code);$.ajax({type: "post",url: "/example.php",data: { line_code: line_code},dataType: "json",success: function (ret) {console.log(ret.success);var tmp = '<option value="">全部</option>';if (ret.success) {var data = ret.data;console.log(data);var length = data.length;for(var i=0;i<length;i++){tmp += '<option value="'+data[i].sch_code+'" >'+data[i].sch_code+'</option>';}console.log(tmp)$('#sch_code').empty();$('#sch_code').append(tmp);}}});});</script>
PHP后台代码片段
<?php$line_code = $_GPC['line_code'];if(!empty($line_code)) {$sch_codes = pdo_getall('zc2_ticket_order',['line_code'=>$line_code],'sch_code');}echo json_encode(['success'=>'true','msg'=>'请求成功','data'=>$sch_codes]);exit();