AJAX代码格式

var request;
//XMLHttpRequest的创建
function createRequest(url){
	if(window.XMLHttpRequest){
		request = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			request= new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e){
				
			}
		}
	}
	request.onreadystatechange = getResult;
	request.open("get",url,true);
	request.send(null);
}

//ajax回调函数
function getResult(){
	if(request.readyState ==4 && request.status == 200){
		document.getElementById("select02").innerHTML = request.responseText;
	}
}

//ajax触发函数 负责生成url
function checkSelect(){
	var url = "/address/SelectServlet?select="+document.getElementById("select01").value;
	createRequest(url);
}

  一般直接使用 new XMLRequest()即可

posted @ 2015-12-20 11:09  WhyToHow  阅读(270)  评论(0编辑  收藏  举报