Created
December 7, 2016 08:13
-
-
Save ElishaKay/f11ea52b472bee0dd4316e331e5fc08e to your computer and use it in GitHub Desktop.
AngularJS $http Service (GET XML)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<title>$http Service | AngularJS</title> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js"></script> | |
<script type="text/javascript"> | |
<!-- | |
(function() { | |
var app = angular.module('app', []); | |
app.controller('Controller', ['$scope', '$http', '$window', function($scope, $http, $window) { | |
$scope.xml = ''; | |
$http({ | |
method : 'GET', | |
url : 'http://curtaincall.weblike.jp/prog/php/xml.php', | |
timeout : 10000, | |
params : {}, // Query Parameters (GET) | |
transformResponse : function(data) { | |
// string -> XML document object | |
return $.parseXML(data); | |
} | |
}).success(function(data, status, headers, config) { | |
console.dir(data); // XML document object | |
$scope.xml = data.documentElement.innerHTML; | |
}).error(function(data, status, headers, config) { | |
$window.alert('通信に失敗しました.'); | |
}); | |
}]); | |
})(); | |
//--> | |
</script> | |
</head> | |
<body ng-controller="Controller"> | |
<section> | |
<h1>$httpサービス GET (Response is XML)</h1> | |
<p ng-bind="xml"></p> | |
</section> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment