AJAX省市区三级联动下拉列表实现 JAVA开发
来源:互联网 发布:sql注入过安全狗 编辑:程序博客网 时间:2024/05/18 02:26
此小程序的功能主要是采用异步请求方式从数据库中调取省市区信息显示到下拉列表:
代码如下:
建立数据库中的代码和一些配置文件信息就省略了,主要有JavaScript中的代码为:
$(document).ready(function(){
$.get("getProvince.do",function(result){
$("#showp").html(result);
});
})
varxmlhttp;
functionmysend(str){
$(document).ready(function(){
$("#show2").html("");
})
varshow = document.getElementByIdx_x_x_x_x_x("show");
show.innerHTML= "";
varprovince = document.getElementByIdx_x_x_x_x_x("province").value;
if(province!=0){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 &&xmlhttp.status==200){
show.innerHTML = xmlhttp.responseText;
}
}
var ss = encodeURIComponent(str);
xmlhttp.open("GET","getCity.do?provinceid="+ss,true);
xmlhttp.send(null);
}
}
function myarea(str){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();