index.php
用户名:
<p><button id="regbtn" onclick="chkveri(),ajaxfunction()">注册</button></p>
</section>
<span id="s31"></span> <span id="s32"></span>
<script src="js/ajax.js"></script>
<script src="js/j.js"></script>
<?php
// put your code here
?>
</body>
js/ajax.js
var xmlHttp;
/* 设置 */
function $(id){
return document.getElementById(id);
}
function ajaxfunction(){
if(window.ActiveXObject){//usually for old IE
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
if(window.XMLHttpRequest){//for new IE and other browers, such as Chrome
xmlHttp=new XMLHttpRequest();
}
xmlHttp.onreadystatechange=readyStateChangHandle;
var username=$(‘username’).value;
url=“chkuser.php”;//;the page applying Ajax
url+="?username="+username;
xmlHttp.open(“GET”,url,true);
xmlHttp.send();
}
function readyStateChangHandle(){
if(xmlHttp.readyState=4&&xmlHttp.status=200){
xmlDoc=xmlHttp.responseText;
var s3=document.getElementById(“s31”);
s3.innerHTML= xmlDoc;
}
}