您正在使用 IPV4 [3.82.232.31] 访问本站,您本次已经查看了 1 页
用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器
悟空收录网       [公益]保护绿色环境,构建和谐社会      

【腾讯云】 爆款2核2G3M云服务器首年 61元,叠加红包再享折上折      
[公益] 地球是我家,绿化靠大家      
2024年 清明节 006
2024年 劳动节 033
2025年 元 旦 278
2025年 春 节 306
 
您现在的位置:首页 >> PHP >> 内容
本类新增
本类热门
用AJAX实现php用户名验证
内容摘要: //该文件为register.php,在客户端htmlheadtitle用户注册/titlemeta http-equiv = 'content-type' content = 'text/html;charset=utf-8'/script type = 'text/javascript' //创建ajax引擎function getXmlHttpObje......
//该文件为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 = "";

//验证用户名是否存在

function checkName(){

//1号线

myXmlHttpRequest = getXmlHttpObject();


//判断创建成功?

if(myXmlHttpRequest){

//通过myXmlHttpRequest对象发送请求到服务器的某个页面

//第一个参数表示请求的方式, "get"/"post"

//第二个参数指定url,对哪个页面发出ajax请求(本质仍然是HTTP请求)

//第三个参数.true表示使用异步机制,false表示不使用异步机制


//注意:此处如果"username"和"="之间有空格,否则会出错,在服务器端接收不到"username";

//注意:如果"="之后有空格则将此空格也作为接收到的username的值的一部分。

//即在服务器端收到的username的值=“ ”(即空格)+从客户端发送的username值。

var url = "/AjaxTest/registerProcess.php?username=" + $("username1id").value;

//window.alert(url);


//打开请求

myXmlHttpRequest.open("get",url,true);

//指定回调函数.process是个函数名

myXmlHttpRequest.onreadystatechange = process;


//真正发送请求。如果是get请求则填入null即可

//如果是post请求,则填入实际的数据

//2号线

myXmlHttpRequest.send(null);


}

}


//回调函数

function process(){

//window.alert("这是回调函数" + myXmlHttpRequest.readyState);

//我要取出从registerProcess.php页面返回的数据


if(myXmlHttpRequest.readyState == 4){


//取出值,根据返回信息的格式而定

//window.alert("服务器返回" + myXmlHttpRequest.responseText);

//4号线

$('myResponse').value = myXmlHttpRequest.responseText;

}


}


function $(id){

return document.getElementById(id);

}

</script>

</head>

<body>

<form action = "" method = "post">

用户名:<input type = "text" name = "username1" id = "username1id" >

<input type = "button" onclick = "checkName();" value = "验证用户名">

<input style = "border-width: 0; color: red" type = "text" id = "myResponse">

<br/>

密码:<input type = "password" name = "password"><br/>

电子邮件:<input type = "text" name = "email"><br/>

<input type = "submit" value = "用户注册">

</form>

<form action = "" method = "post">

用户名:<input type = "text" name = "username2" >


<br/>

密码:<input type = "password" name = "password"><br/>

电子邮件:<input type = "text" name = "email"><br/>

<input type = "submit" value = "用户注册">

</form>

</body>

</html>

//该文件为registerProcess.php,在服务器端

<?php

//接收数据

$username = $_GET["username"];


if($username=="shunping"){

echo "用户名不可用";

}else{

echo "用户名可用";

}

echo "用户名:".$username;//3号线

?>

版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
上一篇:textarea多行数组分割处理方法

 

下一篇:用PHP查询域名状态whois的类

发布日期:2021/6/15
手机扫二维码直达本页
发布时间:12:34:56
点  击:4
录  入:壹家怡园
相关文章
Baidu
YiJiaCMS 7.3.8 build231228(MSSQL) 闽ICP备05000814号-1
本空间由腾讯云(轻量应用服务器)提供,Cloudflare提供加速防护
运行时间载入中.....