当前位置: 代码迷 >> Ajax >> ajax套数
  详细解决方案

ajax套数

热度:246   发布时间:2012-10-08 19:54:56.0
ajax套路
var req;
	
function UserNameCheck(){
     var username = document.getElementById('username').value;
     var url = "pre?user_name=" + escape(username);
     if (window.XMLHttpRequest) {
          req = new XMLHttpRequest();
     }else if (window.ActiveXObject) {
          req = new ActiveXObject("Microsoft.XMLHTTP");
     }
     if(req){
          req.open("GET", url, true);
          req.onreadystatechange = callback;
          req.send(null);        
     }	
}	
	
function callback() {	
    if (req.readyState == 4) {
        if (req.status == 200) {
             parseMessage();
                 // update the HTML DOM based on whether or not message is valid
        }else{
            alert ("Not able to retrieve description" + req.statusText);
        }       
    }
    else
    {
    	document.getElementById("check_username").innerHTML = "正在验证用户名....";
    }
}

function parseMessage() {
    var xmlDoc = req.responseXML.documentElement; 
    var node = xmlDoc.getElementsByTagName('info');
  document.getElementById('check_username').innerHTMLnode[0].firstChild.nodeValue;
}
  相关解决方案