Blogger Information
Blog 26
fans 0
comment 0
visits 16602
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
AJAX的第一种用法
瘦不下来的博客
Original
509 people have browsed it

html代码:

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>3.$.ajax()</title>
</head>
<body>
	<h2>用户登录</h2>
	<form>
		<p>用户名:<input type="text" name="name"></p>
	</form>
</body>
</html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
	

	 //当失去焦点时时行验证
	 $(':input').blur(function(){
	 	
		$.ajax({
			//请求的服务器资源,必须是字符串
			url: 'api/demo.php',

			//客户端的请求类型:GET,POST...,推荐大写
			type: 'GET',

		
			data: $('form:first').serializeArray(),

			//成功回调
			success: function(msg,status,xhr) {
				console.log(msg)
				$('p span').empty()
				$('p').append($(msg))
			}			
		})
	




	 })
	
	
	




	
	
</script>

运行实例 »

点击 "运行实例" 按钮查看在线实例

php代码:

user

实例

<?php 
// print_r($_GET);exit;
// 用数组模拟数据库中的已存在的用户名,这是不允许使用的
$nameList = ['admin','peter','php'];
//这是当前用户提交的用户名
$userName = $_GET['name'];

//判断用户名是否为空
if (strlen(trim($userName))==0) {
	echo '<span style="color:red">用户名不能为空</span>';
//判断用户名是否为纯数字,这是不允许的
} else if (is_numeric($userName)) {
	echo '<span style="color:red">用户名不能为纯数字</span>';
//判断用户名是否已经被注册
} else if (in_array($userName, $nameList)) {
	echo '<span style="color:red">用户名太抢手了,换一个</span>';
//用户名可用提示
} else {
	echo '<span style="color:green">恭喜,用户名可用</span>';
}

运行实例 »

点击 "运行实例" 按钮查看在线实例



index

实例

<?php 
echo '<h1 style="color:red">登录成功</h1>';

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post