I am new to Angular.
I am trying to get Angular work with AJAX calls.
When I access http://localhost:9091/jerseyservlet/jerseyrest/org/orgId/DEY
via browser or any REST client I get the following:
<users>
<user>
<id>0</id>
<name>User 0</name>
<owningorgid>0</owningorgid>
<position>Test User</position>
<email>user0@org.com</email>
<suspended>false</suspended>
<locked>false</locked>
</user>
</users>
When I execute he program, I always get request rejected
printed on console.
My Angular Code is as contained below:
I have copied the code from here
//Creating an Angular Module named NeptuneDemo by registering the name with Angular Module constructor.
var neptuneDemo=angular.module('NeptuneDemo', []);
neptuneDemo.factory('simpleFactory',['$http','$q',function ($http,$q){
return{
sendRequest: function(){
var deffered = $q.defer();
$http
.get('http://localhost:9091/jerseyservlet/jerseyrest/org/orgId/DEY')
.success(function(xml,status,headers,config){
deffered.resolve(xml);
})
.error(function(xml,status,headers,config){
deffered.reject(xml);
});
return deffered.promise;
}
}
}]);
//Registering NeptuneDemoController with the Angular Module Object neptuneDemo.
neptuneDemo.controller('NeptuneDemoController',['simpleFactory','$scope',function NeptuneDemoController(simpleFactory,$scope){
//defining the displayMessage() method mapped to the input form
$scope.displayMessage = function(){
$scope.users= [];
simpleFactory.sendRequest()
.then(function(data){
console.log('request successful');
console.log(data);
},function (data){
console.log('request rejected');
console.log(data);
});
};
//Defining New Model Object msg
function User(id,name,owningOrgId,position,email,suspended,locked){
this.id=id;
this.name=name;
this.owningOrgId=owningOrgId;
this.position=position;
this.email=email;
this.suspended=suspended;
this.locked=locked;
}
}]);
Issue 2 : I also need help in parsing the XML and populate to the object. Not Sure if jQuery.parseXML() would work. Please let me know any better options.
Thanks for reading the really long post.