`

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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics