AngularJS is a Javascript MVC framework created by Google.It is best framework to build better architecture web projects, especially for RESTful web services.Here is the simple example for calling rest api from AngularJS.
$scope.login = function() {
var aUserName=document.getElementById(‘username’).value; // Username
var aPassword=document.getElementById(‘password’).value; // Password
var symbol = “MSFT”;
var xmlhttp = new XMLHttpRequest();
// XML Input
var xml = ‘<?xml version=”1.0″ encoding=”utf-8″?>’ +
‘<soap:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”>’ +
‘<soap:Body> ‘ +
‘<UserAuthnetication xmlns=”http://www.sample.com/NativeApp”>’ +
‘<userId>’ + aUserName + ‘</userId> ‘ +
‘<password>’ + aPassword + ‘</password> ‘ +
‘</UserAuthnetication> ‘ +
‘</soap:Body> ‘ +
‘</soap:Envelope>’;
// Call api
$http.post(‘http://www.sample.com/NativeApp/Appservice.asmx’, xml, {headers: {‘SOAPActions’: ‘http://www.sample.com/NativeApp/Authnetication’,'Content-Type’: ‘text/xml’}})
.success(function (data) {
if (data) {
$scope.data = data; // Response
}else{
alert(“Login failed. Please enter the valid username and password.”);
}
});
error(function(data) {
});
}
Comments
Post a Comment