<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>getCity.html</title>
<script src="jquery.js"></script>
<script>
//当点击不同的城市,就请求到相应的地区,追加到相应的城市后面,在追加之前先清空里面的东西,以免重复。
function getCity(cityId){
$.ajax({
type: "post",
url: "http://192.168.1.104:8080/shopWeb/service/getcitys",
data:{"provinceId": cityId},
dataType:'json',
success: function(data){
var obj=data.object;
var html="";
for(var i in obj){
html+="<a href='###'>"+obj[i]+"</a>"
}
$("#city"+cityId).empty().append(html);
}
});
}
$(function(){
//获取城市名,当点击不同的城市的时候,执行getCity("+i+")
$.ajax({
type: "POST",
url: "http://192.168.1.104:8080/shopWeb/service/getprovinceForm",
data: {
"version": "1.0.0",
"provinceId": 5
},
dataType: 'json',
success: function(data){
var obj=data.object;
var html="";
for(var i in obj){
html+="<a href='###' οnclick='getCity("+i+")'>"+obj[i]+" <span id='city"+i+"'></span></a><br>"
}
$("#pro").append(html);
}
});
});
</script>
</head>
<body>
<div id="pro">
</div>
</body>
</html>