Skip to content

Instantly share code, notes, and snippets.

@ElishaKay
Created December 7, 2016 08:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElishaKay/f11ea52b472bee0dd4316e331e5fc08e to your computer and use it in GitHub Desktop.
Save ElishaKay/f11ea52b472bee0dd4316e331e5fc08e to your computer and use it in GitHub Desktop.
AngularJS $http Service (GET XML)
<!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