<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>淘宝注册页面</h1>
<input type="text" placeholder="请输入用户名" id="userText" />
</body>
</html>
<script type="text/javascript">
document.querySelector("#userText").onblur = function(){
var ajaxObj = new XMLHttpRequest();
ajaxObj.open('GET','ajax_check.php?userName='+this.value);
ajaxObj.send();
ajaxObj.onreadystatechange = function(){
if(ajaxObj.readyState==4&&ajaxObj.status==200){
console.log('接受数据成功');
console.log(ajaxObj.responseText);
if(ajaxObj.responseText=='have'){
alert("此用户名已经存在");
}else{
alert("此用户名可以使用");
}
}
}
}
</script>