Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Angularjs http service - Example

DZone's Guide to

Using Angularjs http service - Example

· Integration Zone
Free Resource

Migrating from On-Prem to Cloud Middleware? Here’s what Aberdeen Group says leading companies should be considering. Brought to you in partnershp with Liaison Technologies

Here I will show a sample angularJs http get request.

$scope.loadCustomerDetails = function(customerId) {

		var responsePromise = $http.get('/customerDetails.htm',{
			params : {
				data : customerId
			}
		});

		responsePromise.success(function(data, status, headers, config) {
			
			$scope.custDetails = data;
			
		});
		responsePromise.error(function(data, status, headers, config) {
			alert("Request failed!");
		});

	};


loadCustomerDetails is an angularjs function which takes one argument - customerId. Within this function, we make an ajax request to a REST endpoint 'customerDetails.htm' . This endpoint return data in json format. We are using promise to catch the result. Promise is an interface for interacting with an object that represents the result of an action that is performed asynchronously, and may or may not be finished at any given point in time.

If the request is a success, then the control goes to the responsepromise.success() function else to the error function.

Hope you got an into to the angularjs http service.

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}