js事件
$('#ProvinceId').change(function(){
var parentId = $(this).val();
$.ajax({
url: '{sh::U("OpenStore/ajax","todo=getCity")}',
type: 'POST',
data: 'parentId='+parentId,
dataType:'json',
success: function(json) {
if (json.status == 1) {
var optionCity = "<option value=''>==请选择==</option>";
$.each(json.info,function(i,n){
optionCity += "<option value="+i+">" + n + "</option>";
});
var optionCounty = "<option value=''>==请选择==</option>";
// 重置市、县
$('#CityId').html(optionCity).val('');
$('#CountyId').html(optionCounty).val('');
} else {
layer.msg('获取数据异常');
}
}
});
});
$('#CityId').change(function(){
var parentId = $(this).val();
$.ajax({
url: '{sh::U("OpenStore/ajax","todo=getCounty")}',
type: 'POST',
data: 'parentId='+parentId,
dataType:'json',
success: function(json) {
if (json.status == 1) {
var optionCounty = "<option value=''>==请选择==</option>";
$.each(json.info,function(i,n){
optionCounty += "<option value="+i+">" + n + "</option>";
});
// 重置县
$('#CountyId').html(optionCounty).val('');
} else {
layer.msg('获取数据异常');
}
}
});
});
ajax
public function ajax() {
$todo = $this->_request('todo','trim');
$data = array('status'=>0,'msg'=>'','info'=>array());
switch ($todo) {
case 'getCity':
$parentId = $this->_post('parentId','trim');
$getAreaData = $this->integral->getArea('2',$parentId); // 获取市
if ($getAreaData['status'] == 1) {
$citys = $getAreaData['CustomProperties'];
$data['status'] = 1;
$data['info'] = $citys;
$data['msg'] = '获取成功';
} else {
$data['status'] = 9;
$data['msg'] = '获取异常';
}
$this->ajaxReturn($data,'JSON');
break;
case 'getCounty':
$parentId = $this->_post('parentId','trim');
$getAreaData = $this->integral->getArea('3',$parentId); // 获取市
if ($getAreaData['status'] == 1) {
$countys = $getAreaData['CustomProperties'];
$data['status'] = 1;
$data['info'] = $countys;
$data['msg'] = '获取成功';
} else {
$data['status'] = 9;
$data['msg'] = '获取异常';
}
$this->ajaxReturn($data,'JSON');
break;
default:
# code...
break;
}
}