This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
http.html
52 lines (49 loc) · 1.55 KB
/
http.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>$http - AngularJS Test</title>
<style type="text/css">
.test-div {margin:15px;padding:15px;border:1px solid #ccc;}
</style>
</head>
<body>
<div class="test-div" ng-controller="myCtrl">
{{respData}}
</div>
<script type="text/javascript" src="static/js/angular-1.5.8.js"></script>
<script type="text/javascript">
/**
* $http is an AngularJS service for reading data from remote servers.
* The AngularJS $http service makes a request to the server, and returns a response.
* $http service several shortcut methods:
* .delete()
* .get()
* .head()
* .jsonp()
* .patch()
* .post()
* .put()
*
* The response from the server is an object with these properties:
* .config the object used to generate the request.
* .data a string, or an object, carrying the response from the server.
* .headers a function to use to get header information.
* .status a number defining the HTTP status.
* .statusText a string defining the HTTP status.
*/
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl", function($scope, $http) {
$http({
method: "GET",
url: "data/players.json"
}).then(function mySuccess(resp) {
$scope.respData = resp.data;
}, function myError(resp) {
$scope.respData = resp.statusText;
});
});
</script>
</body>
</html>