菜单

ajax+php实现无刷新验证手机号的实例

2017年12月28日 - PHPer

一款简单的无刷新验证手机号是否注册:

客户端实现:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
#btn{width:80px;height:30px;}
</style>
</head>
<body>
<form> 
请输入手机号:
<input type="text" id="name" name="name">
<input type="button" onclick="show()" id="btn" value="验证">
</form>
<p id="txt"></p>
<script>
var usernamereg = /^1(3|4|5|7|8)\d{9}$/;
function show(){	
var name=document.getElementById("name").value;
var xmlHttp=new XMLHttpRequest();
var url="post.php";
xmlHttp.onreadystatechange=function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	if(!usernamereg.test(name)){
 		document.getElementById("txt").innerHTML="手机号有误";
	}else{
 	document.getElementById("txt").innerHTML=xmlHttp.responseText 
 		} 
 	}
}
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("name=" + name);
} 
</script>
</body>
</html>

服务端实现:

<?php
$con = mysqli_connect('localhost', 'username', 'password');
if(! $con )
{
 die('连接失败: ' . mysqli_error($con));
}
mysqli_select_db($con,'bdm256727651_db');
$username = "select userName FROM Forms where userName = '$_POST[name]' ";
$result = mysqli_query($con,$username );
$rows=mysqli_num_rows($result);
if($rows){
	echo "手机号已注册"	;
	exit;
}else{
	echo "手机号可用";	
}
mysqli_close($con)
?>

ajax+php实现无刷新验证手机号的实例》有14个想法

Infest

What do you study? il valium dopo quanto fa effetto Analysts say that group, based in Yemen, is still plotting to strike the American homeland.

回复
Kermit

I’ll put him on amaryllis bulb buy online Dozens of others in the US and Canada have tried to grow the plant – a type of horseradish that originates in Japan, where it is found growing naturally in rocky river beds – but almost all have failed.

回复
Virgilio

Yes, I play the guitar how to order prednisone online
Lonsdale was actually Konon Molody, a Russian who ran a spying operation at the Admiralty Underwater Weapons Establishment at Portland in Dorset

回复
Kaitlyn

Go travelling diet pep reviews Meanwhile, the gates of “Swamp Safari” still say “Trespassers Will Be Eaten”, exactly as they did when Roger Moore’s 007 escaped gun-wielding goons by leaping on the backs of crocodiles to safety.

回复
Julio

Get a job blue goo cracked heel ingredients
IIf you’ve been keeping up with the news, it’s clear that if you want to punch out your girlfriend and avoid jail time, Atlantic County, N.J

回复
Alonzo

Where’s the postbox? maxman pills review currency retraced its gains after earlier hitting a12-year high versus the euro, pressured by a third-straightdecline in monthly U.S

回复
Thebest

Could I have a statement, please? estrace cream side effects spotting However, consultants and others working at banks, government agencies and even the phone companies note that, while many people have mobile money accounts — usually with the phone companies – few are actively used

回复
Wayne

What qualifications have you got? xenical orlistat 120 mg price Destiny is not any old computer game, it is being touted as the world's most expensive, with a massive development budget

回复
Incomeppc

I’d like to cancel a cheque redotex que tan malo es As for why the mummies were floating in a polluted sewer, authorities can’t say for sure — but they have their suspicions

回复
Jorge

I want to make a withdrawal apakah valium itu The TTP also survived because of a lack of commitment by the Pakistani army to completely eradicate it, brought about by the army's desire to discriminate between elements that were useful to the country's foreign policy and those that were not.

回复
Teddy

Is this a temporary or permanent position? cytosport 100 whey protein powder 6-pounds reviews Before chauffeurs get to turn off the engine they have to pass through a Los Angeles Police Department (LAPD) security check – explosives K9 and all – and even then plain clothes LAPD officers will be there to keep watch.

回复
Terrence

Did you go to university? naltrexone revia side effects At the moment the scientists discovered 1,876 planets that are orbiting around stars that is not the earth’s sun

回复
Cornelius

What’s your number? define clean balance sheet In the choppy season-opening win against Oklahoma State, Winston seemed to force the ball to receiver Rashad Greene, who finished with 203 yards on 11 receptions

回复

发表评论

电子邮件地址不会被公开。