Skip to content

Instantly share code, notes, and snippets.

@daver182
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daver182/10977907 to your computer and use it in GitHub Desktop.
Save daver182/10977907 to your computer and use it in GitHub Desktop.
Getting data from a ASP Webservice
//Then in the app.js file we set the interceptor
var app = angular.module('appName', ['xml'])
.config(function ($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/view1.html',
controller: 'Controller1',
})
.when('/view2', {
templateUrl: 'views/view2.html',
controller: 'Controller2',
})
.otherwise({
redirectTo: '/'
});
$httpProvider.responseInterceptors.push('xmlHttpInterceptor');
});
//And in some service, we make the request in parse the results
$http.post('http://url.to.server').then(function(response){
var items = [],
els = response.xml.find('Table'),
item,
i;
for (i = 0; i < els.length; i += 1) {
item = angular.element(els[i]);
var children = item.children();
items.push({
id: children[0].childNodes[0].nodeValue,
name: children[1].childNodes[0].nodeValue,
password: children[2].childNodes[0].nodeValue,
email: children[3].childNodes[0].nodeValue,
phone: children[4].childNodes[0].nodeValue,
address: children[5].childNodes[0].nodeValue
});
}
}, function(){
console.log('An error ocurred');
});
return items;
<!--We are going to use this XML Module for Angularjs
//https://github.com/johngeorgewright/angular-xml-->
<!--We call the XML script before app.js-->
<html>
<head>
<script src="scripts/angular-xml/angular-xml.js"></script>
<script src="scripts/app.js"></script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment