加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax实现检测当前注册用户是否存在

发布时间:2020-12-16 00:41:57 所属栏目:百科 来源:网络整理
导读:请求页面:ajax.html !doctype html html head meta charset="utf-8" /head body 姓名:input type="text" id="uname"/ span id="msg"/spanbr/ /body /html script function $(id){ return document.getElementById(id); // 根据指定的 id 属性值得到对象 } $

请求页面:ajax.html

<!doctype html>

<html>

<head>

<meta charset="utf-8">

</head>

<body>

姓名:<input type="text" id="uname"/ ><span id="msg"></span><br/>

</body>

</html>

<script>

function $(id){

return document.getElementById(id); //根据指定的 id 属性值得到对象

}

$('uname').onkeyup=function(){

//在键盘按键被松开时触发事件

var n = $('uname').value; //将对象的值赋给新的变量

var x = new XMLHttpRequest(); //创建ajax请求对象

x.open('GET','ajax.php?n='+n,true); //设置传送方式和路径

x.onreadystatechange=function(){ //

if(x.readyState==4 && x.status==200){

$('msg').innerHTML = x.responseText; //在ID为msg的标记中载入获取的数据

}

}

x.send();//发送数据

}

</script>


响应检测页面:

<?php

if(isset($_GET['n'])&&$_GET['n']!=""){

$n = $_GET['n'];

if($n=='admin'){ //用admin代表数据库查询到的值

echo '<font color=red>已经存在</font>';

}else{

echo '<font color=green>不存在,可以使用</font>';

}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读