ajax提交表单实现网页无刷新注册示例_基础知识

WBOY
Release: 2016-05-16 16:49:18
Original
1658 people have browsed it

Ajax 无刷新

复制代码代码如下:

var xmlHttp;
uName() //用户名失去焦点时
{
if(all.uname.=="")
{
all.l1.innerHTML="不能为空!";
setTimeout("close(1)",1500);
return;
}
else
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.onreadystatechange=deal; //回调函数
var url="aJax.aspx?user='"+all.uname.+"'"; //将要跳转到检测用户名的页面
xmlHttp.open("get",url,true); //用 get 模式提交表单 到 url ;并启动 一步处理
xmlHttp.send(null); //发送
}
}
deal()
{
//alert(xmlHttp.readystate+"__"+xmlHttp.status);
if(xmlHttp.readystate!=4)
{return; }

if(xmlHttp.status!=200) //等于500 时是 sql 语句或数据库的错误
{return;}
//

var num = xmlHttp.responseText; //接收服务器发送的信息
//alert(num);
all.l1.innerText="";
if(num>0)
{
all.l1.innerText="次用户名已被使用!";
}
else
{
all.l1.innerText="√";
}

}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!