ajax学习

ajax学习

var xmlHttp;
function createXMLHTTPRequest(){

if(window.ActiveXObject){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e1){
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
//xmlHttp.setRequestHeader("Content-Type","text/xml");
//xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else{
alert("不支持Ajax");
}
}
function doRequestUsingGet(){
createXMLHTTPRequest();
xmlHttp.open("GET","jsp/ajaxServer.jsp?name=国安&timeStamp="+(new Date().getTime()),true);
xmlHttp.onreadystatechange = callbackHander;
xmlHttp.send(null);
}

function doRequestUsingPost(){
createXMLHTTPRequest();
xmlHttp.open("POST","jsp/ajaxServer.jsp",true);
xmlHttp.onreadystatechange = callbackHander;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("name=国安&timeStamp="+(new Date().getTime()));
}

function callbackHander(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
alert(xmlHttp.responseXML);
}
}
}
function checkUser(){
//doRequestUsingGet();
doRequestUsingPost();
}





你可能感兴趣的:(jsp,xml,Ajax,Microsoft)