1. 程式人生 > >angularjs服務 $http

angularjs服務 $http

.data control param get app $scope con response AS

angularjs服務 $http

<!DOCTYPE html>
<html ng-app="test">
<head>
<meta charset="utf-8">
<script src="angular.min.js"></script>
<script>
var app=angular.module(‘test‘,[]);
// alert(app);
app.controller(‘zhangsan‘,function($scope,$http){
	// $http.get(url,參數)
	// $http.post()
	// a.php?a=xxx&b=xxx=>
	$http.get(‘a.php‘,{
			params:{a:12,b:6},
			responseType:‘json‘
		}).then(function(res){
		alert(res.data+5);
	},function(){
		alert("失敗了");
	});
});
</script>
</head>
<body ng-controller="zhangsan">
	
</body>
</html>

  a.php

<?php
echo $_GET[‘a‘]+$_GET[‘b‘];
?>

  

angularjs服務 $http