Blogger Information
Blog 250
fans 3
comment 0
visits 322861
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery --通用的$.ajax()链接数据方式
梁凯达的博客
Original
1017 people have browsed it

实例

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>Document</title>
</head>
<body>
	<button id="buts">ajax通用</button>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
	//以下为通用的方式使用ajax
	$('#buts').click(function(){
		var num = 10;
		//$.ajax({})
		$.ajax({
			//参数1: url  设置访问的Php文件
			url:'06_ajax.php',
			//参数2:data:用于传值
			data:'id=1000',
			//参数3:用于设置连接的方式
			type:'GET',
			//参数4:success成功后执行什么
			success:function(data){
				num = 100;
				console.log(data);
			},
			//参数5:error 失败后执行什么
			error:function(){
				alert('ajax错误');
			},
			//timout 用于设置最大等待时间,无设置默认不填
			//当timout设置的时间内ajax未访问成功请求数据的话,则判定为失败
			timout:3000,
			//async 是否异步,如果异步为true,同步为false
			async:false
		});
		alert(num);
	})
</script>
</html>

运行实例 »

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

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