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

ajax jquery 异步表单验证

发布时间:2020-12-16 00:56:28 所属栏目:百科 来源:网络整理
导读:文件目录: html代码: html head title异步表单验证/titlescript type='text/javascript' src='jquery.js' /scriptscript function checkname(){ //$("input[name='name']").val() $.ajax({ type:"get",url:'index.php',data:"name="+$("input[name='name']

文件目录:


html代码:

<html>
  <head>
    <title>异步表单验证</title>
	<script type='text/javascript' src='jquery.js' ></script>
	<script>
	 function checkname(){
	 //$("input[name='name']").val()
	   $.ajax({
	   type:"get",url:'index.php',data:"name="+$("input[name='name']").val(),success:function(msg){
	   $("#show").append(msg);
	   }
	   });
	   
	 }
	</script>
  </head>
  <body>
    <form name='form'>
      <input name='name' type='text'  onblur='checkname();'>
	  <span id='show'></span><br />
	  <input type='submit' name='submit' value='提交' />
	</form>
  </body>
</html>

php代码:
<?php
   //进行连接服务器
   $link=mysql_connect('localhost','root','sanyue');
   if(!$link){
    die('连接失败:'.mysql_error());
   }
   //进行连接数据库
   mysql_select_db('excour',$link);
   
  // $name=$_GET['name'];
   echo $name;
   $sql="select name from user_info where name='$name'";

   //执行查询语句
   $result=mysql_query($sql);


   if(mysql_num_rows($result) != 0){
		echo "<font color='red'>名字太受欢迎,换一个吧</font>";
	}else{
		echo "<font color='blue'>成功</font>";
	}  
   
   //进行释放查询结果集
   mysql_free_result($result);
   //关闭数据库连接
   mysql_close($link);
?>

运行结果示例:

(编辑:李大同)

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

    推荐文章
      热点阅读