日期:2014-05-16 浏览次数:20591 次
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; }