zepto中的ajax请求

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>zepto中的ajax请求</title>
</head>
<body>
	<script type="text/javascript" src="../../lib/zepto.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			// get请求方式简写  
			$.get('urlxxx',[data],function(response){
			  $(document.body).append(response);//response是后台返回的json数据或者txt数据
			},[dataType]); //dataType 可以指定后台给我们返回的数据类型

			// post 请求方式简写
			$.post('urlxxx', { sample: 'payload' }, function(response){
			 	
			},[dataType]);
			
			// ajax  完整的写法
			$.ajax({
			  type: 'GET',
			  url: 'urlxxx',
			  data: { name: 'Zepto.js' },
			  dataType: 'json',
			  success: function(data){
			    this.append(data.project.html)
			  },
			  error: function(xhr, type){
			    alert('Ajax error!')
			  }
			})
		});
	</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/CSDN_yqf1994/article/details/89237660