1. 程式人生 > >angular的http三種請求方式

angular的http三種請求方式

就是get post json 三種請求方法

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>http</title>
		<script src="day2/src/angular.js"></script>
	</head>
	<body ng-app="app">
		<div ng-controller="fristController">
			
		</div>
		
		<script type="text/javascript">
			var app = angular.module('app',[]);
			app.controller('fristController',['$scope','$http',function($scope,$http){
				
				// get方式
//				$http.get('test.json').success(function(data){
//					console.log(data)
//				})
//				.error(function(data){
//					console.log(data)
//				});
				
				
				// post方式
//				var postData = {name:'zhangsan',age:30}
//				$http.post('test.json',postData).success(function(data){
//					console.log(data)
//				})
//				.error(function(data){
//					console.log(data)
//				});
				
				
				//jsonp方式
				$http.jsonp('test.json')
				.success(function(data){
					console.log(data);
				})
				.error(function(){
					console.log(data);
				})
			}])
		</script>
	</body>
</html>