ajax三级联动例子

 我来答
woyani2
推荐于2016-04-12 · TA获得超过211个赞
知道小有建树答主
回答量:103
采纳率:0%
帮助的人:102万
展开全部
不能给你实例,你自己参照我所做的,自己借鉴吧,是用Jquery+ajax实现的
<script>
function getDistrict(){
var obj_city = document.getElementById("city");
var city_Index = obj_city.selectedIndex;
var city_Value = obj_city.options[city_Index].value;
BindUnit_District(city_Value);
}
function BindUnit_District(id) {
$.ajax({
url: "../city/district.html?id="+id,
dataType: 'json', //返回的类型为json
success: function(result) { //成功时执行的方法
try {
$("#district").empty(); //清空下拉列表
$(result).each(function(i, item) {
$("#district").append(" <option value='" + item.id + "'>" + item.name + "</option>");
}
);
}
catch (e) {
alert(e);
return;
}
},
error: function(result, status) { //出错时会执行这里的回调函数
if (status == 'error') {
alert(status);
}
}
});
}
</script>

后台JAVA代码:
public class CityD {
App app = App.getInstance();
EntityManagerFactory emf = app.getEntityManagerFactory();
org.springframework.orm.jpa.JpaTemplate jpaTemplate = new org.springframework.orm.jpa.JpaTemplate(emf);
/**
* Ajax请求
* @param id
* @return 行政区
* @throws Exception
*/
@SuppressWarnings("unchecked")
@GET
@Produces({ MediaType.APPLICATION_JSON }) //返回类型为json
public java.util.List<District> linkage(@QueryParam("id") String id) throws Exception {
//根据id查询出City下所有的行政区
java.util.List<District> d = jpaTemplate.find("select d from District d where d.city.id='"+id+"'");
return d;
}
}

希望你能自己领悟
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式