在一个文本标签中输入电子邮件,当onblur时触发验证事件,到数据库检验是否已经存在该用户,其中dispear方法即为onblur事件触发的方法。已经验证服务器已经收到本地发送的数据并且验证成功,但是echo不回去。
js代码如下:
var myXmlHttpRequest;
function getXmlHttpObject(){
var xmlHttpRequest;
try{
xmlHttpRequest=new XMLHttpRequest();
}
catch(e){
try{
xmlHttpRequest=new ActiveXObject("Msxml2.HMLHTTP");
}
catch(e){
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttpRequest;
}
function isExist(email){
myXmlHttpRequest=getXmlHttpObject();
if(myXmlHttpRequest){
alert("hello"+email);
var url="/renren/register_legal_Process.php";
var data="email="+email;
myXmlHttpRequest.open("post",url,true);
myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
// 指定回调函数
myXmlHttpRequest。onreadystatechange=deal;
myXmlHttpRequest.send(data);
//alert(myXmlHttpRequest.readyState);
}
}
function deal(){
alert('hello');
if(myXmlHttpRequest.readyState==4){
var isExist=myXmlHttpRequest.responseText;
if(isExist=="exist"){
$("focus1").style.display="none";
$("wrong1").style.display="none";
$("duihao").style.display="none";
$('wrong5').style.display="block";
}else if(isExist=="notexist"){
$("focus1").style.display="none";
$("wrong1").style.display="none";
$("wrong5").style.display="none";
$("duihao").style.display="block";
}
}
}
function $(id){
return document.getElementById(id);
}
function disappear(ref1,ref2,ref3,ref4){
var app=$(ref1);
var tmp1=$(ref2);
var tmp2=$(ref3);
var tmp3=$(ref4);
var str=tmp1.value;
var reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi; if(!reg.test(str))
{
tmp3.style.display="none";
app.style.display="none";
$("wrong5").style.display="none";
tmp2.style.display="";
}
else
{
/*
* tmp2.style.display="none"; app.style.display="none";
* tmp3.style.display="";
*/
//var email=$('email').value;
isExist(str);
}
if(str=="")
{
app.style.display="none";
tmp2.style.display="none";
tmp3.style.display="none";
}
}
服务器端代码如下:
<?php
header("Content-type:text/html;charset=utf-8;");
header("Cache-Control:no-cache");
require_once 'UserService.class.php';
$email=$_POST['email'];
//file_put_contents("log.txt",$email."\r\n",FILE_APPEND);
$userService=new UserService();
$isExist=$userService->isExist($email);
if($isExist){
file_put_contents("log.txt","exist"."\r\n",FILE_APPEND);
echo "exist";
}else{
file_put_contents("log.txt","notexist"."\r\n",FILE_APPEND);
echo "notexist";
}?>xmlhttprequestajax服务器
js代码如下:
var myXmlHttpRequest;
function getXmlHttpObject(){
var xmlHttpRequest;
try{
xmlHttpRequest=new XMLHttpRequest();
}
catch(e){
try{
xmlHttpRequest=new ActiveXObject("Msxml2.HMLHTTP");
}
catch(e){
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttpRequest;
}
function isExist(email){
myXmlHttpRequest=getXmlHttpObject();
if(myXmlHttpRequest){
alert("hello"+email);
var url="/renren/register_legal_Process.php";
var data="email="+email;
myXmlHttpRequest.open("post",url,true);
myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
// 指定回调函数
myXmlHttpRequest。onreadystatechange=deal;
myXmlHttpRequest.send(data);
//alert(myXmlHttpRequest.readyState);
}
}
function deal(){
alert('hello');
if(myXmlHttpRequest.readyState==4){
var isExist=myXmlHttpRequest.responseText;
if(isExist=="exist"){
$("focus1").style.display="none";
$("wrong1").style.display="none";
$("duihao").style.display="none";
$('wrong5').style.display="block";
}else if(isExist=="notexist"){
$("focus1").style.display="none";
$("wrong1").style.display="none";
$("wrong5").style.display="none";
$("duihao").style.display="block";
}
}
}
function $(id){
return document.getElementById(id);
}
function disappear(ref1,ref2,ref3,ref4){
var app=$(ref1);
var tmp1=$(ref2);
var tmp2=$(ref3);
var tmp3=$(ref4);
var str=tmp1.value;
var reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi; if(!reg.test(str))
{
tmp3.style.display="none";
app.style.display="none";
$("wrong5").style.display="none";
tmp2.style.display="";
}
else
{
/*
* tmp2.style.display="none"; app.style.display="none";
* tmp3.style.display="";
*/
//var email=$('email').value;
isExist(str);
}
if(str=="")
{
app.style.display="none";
tmp2.style.display="none";
tmp3.style.display="none";
}
}
服务器端代码如下:
<?php
header("Content-type:text/html;charset=utf-8;");
header("Cache-Control:no-cache");
require_once 'UserService.class.php';
$email=$_POST['email'];
//file_put_contents("log.txt",$email."\r\n",FILE_APPEND);
$userService=new UserService();
$isExist=$userService->isExist($email);
if($isExist){
file_put_contents("log.txt","exist"."\r\n",FILE_APPEND);
echo "exist";
}else{
file_put_contents("log.txt","notexist"."\r\n",FILE_APPEND);
echo "notexist";
}?>xmlhttprequestajax服务器
解决方案 »
- php无法连接PostgreSQL呢
- 正则问题
- FastCGI Error 错误,高手来帮忙啊!!!
- Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'
- discuz!X2.5问题,急求解,非常急
- PHP链接MYSQL编辑问题
- discuz 模板解析
- lnmp一键安装包性能和单独装一样吗
- 【求】用C++开发php5.5.8所需的整套资源(VS2012)
- 关于tp3.2有时候会出现:_STORAGE_WRITE_ERROR_ 的问题
- 上传图片功能 拿到虚拟空间服务器 不好使了。。急 急 急
- RoundCube Web Mail 连接数据库失败
alert(isExist); //弹出什么结果打开firebug,在控制台看看有不有什么错误