四个下拉框联动 省市区法院选择 js + ajax

js ajax


base = document.getElementById("base").href;


$(document).ready(function() {

$('#provinceId_edit').change(function() {
var p1 = $(this).children('option:selected').val();
$.ajax({
url : base + "/user01/chgProv",
data : {
provinceId : p1,
},
type : 'post',
cache : false,
dataType : 'json',
success : function(data) {
$("#cityId_edit").html("");
$("#cityId_edit").append("");
$.each(data.cityList, function(entryIndex, entry) {
$("#cityId_edit").append("");
});
$("#countyId_edit").html("");
},
error : function() {
}
});
});
$('#cityId_edit').change(function() {
var p1 = $('#provinceId_edit').children('option:selected').val();
var p2 = $(this).children('option:selected').val();
$.ajax({
url : base + "/user01/chgCity",
data : {
provinceId : p1,
cityId : p2,
},
type : 'post',
cache : false,
dataType : 'json',
success : function(data) {
$("#countyId_edit").html("");
$("#countyId_edit").append("");
$.each(data.countyList, function(entryIndex, entry) {
$("#countyId_edit").append("");
});
},
error : function() {
}
});
});
$('.field').change(function() {
var p1 = $('#provinceId_edit').children('option:selected').val();
var p2 = $('#cityId_edit').children('option:selected').val();
var p3 = $('#countyId_edit').children('option:selected').val();
$.ajax({
url : base + "/yellowPage01/leadin/item/getcourt",
data : {
provinceId : p1,
cityId : p2,
countyId:p3,
},
type : 'post',
cache : false,
dataType : 'json',
success : function(data) {
$("#court_edit").html("");
$("#court_edit").append("");
$.each(data.courtList, function(entryIndex, entry) {
$("#court_edit").append("");
});
},
error : function() {
}
});


});
$('#submit_edit').click(function() {
var price = $('#price').val();
var province = $('#provinceId_edit').val();
if(province =="" ){
alert("请选择地市!");
return false ;
}else if(price == ""){
alert("请输入法院/检察院");
return false ;
}else{
$('form').submit();
}
});
});

controller:

// 修改地区后 找出对应的 court
	@RequestMapping(value = { "/leadin/item/getcourt" })
	@ResponseBody
	public Map getCourt(ModelMap model, String provinceId, String cityId, String countyId, HttpSession httpsession, Integer courtId) {
		
		yellowPage01Service.add(model, provinceId, cityId, countyId, courtId);
		Map map = new HashMap();
		map.put("courtList", model.get("courtList"));
		return map;

	}



你可能感兴趣的:(司法黄页下拉菜单)