Blogger Information
Blog 29
fans 0
comment 1
visits 18775
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
$.ajax()的使用-2018年4月11日
小小的菜的博客
Original
472 people have browsed it

代码

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>$.ajax用法</title>
</head>
<body>
	<h2>用户登录</h2>
	<form>
		<p>用户名:<input type="text" name="name"></p>
	</form>
</body>
<script type="text/javascript" src="../0409/js/jquery.js"></script>
<script type="text/javascript">
	// 当失去焦点时验证
	$(':input').blur(function(){
		// 将回调写到$.ajax()中
		$.ajax({
			// 1.请求的服务器资源
			url:'api/demo.php',
			// 2.客户端的请求类型
			type:'GET',
			// 3.从服务器返回的数据格式
			// dataType:'json',
			// 4.异步或者同步
			// async:true,
			// 5.发送的数据
			data:'name='+$(':input').val(),
			// 6.成功回调函数
			success: function(msg,status,xhr){
				// console.log(msg)
				$('p span').empty()
				$('p').append($(msg))
			}
		// 7.错误的回调函数
		})
		
	})
	
</script>
</html>

运行实例 »

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

0410作业.jpg

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