//该文件为register.php,在客户端
<html>
<head>
<title>用户注册</title>
<meta http-equiv = "content-type" content = "text/html;charset=utf-8"/>
<script type = "text/javascript" >
//创建ajax引擎
function getXmlHttpObject(){
var xmlHttpRequest;
//不同浏览器获取对象XmlHttpRequest对象方法不同
if(window.ActiveXObject){
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttpRequest = new XMLHttpRequest();
}
return xmlHttpRequest;
}
/*
function getXmlHttpObject(){
//不同浏览器获取对象XmlHttpRequest对象方法不同
var xmlHttp = null;
try{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}catch(e){
//Internet Explorer
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
*/
var myXmlHttpRequest = "";
//<strong>验证用户名</strong>是否存在
function checkName(){
//1号线
myXmlHttpRequest = getXmlHttpObject();
//判断创建成功?
if(myXmlHttpRequest){
//通过myXmlHttpRequest对象发送请求到服务器的某个页面
//第一个参数表示请求的方式, "get"/"post"
//第二个参数指定url,对哪个页面发出ajax请求(本质仍然是HTTP请求)
//第三个参数.true表示使用异步机制,false表示不使用异步机制
//注意:此处如果"username"和"="之间有空格,否则会出错,在服务器端接收不到"username";
//注意:如果"="之后有空格则将此空格也作为接收到的username的值的一部分。
//即…………………………………………………………………………<p style="COLOR: red; FONT-SIZE: 16px"><strong>本文固定链接:<a target=_blank href="http://www.verydemo.com/demo_c107_i1201.html" target="_blank">http://www.verydemo.com/demo_c107_i1201.html</a></strong></p>
AJAX实现用户名验证
最新推荐文章于 2018-08-05 21:02:49 发布