AngularJS AJAX - $http


$http is an AngularJS service for reading data from remote servers.


AngularJS $http

The AngularJS $http service makes a request to the server, and returns a response.

Output :

Properties of the $http Response Object

The response received from the server using the $http service is an object containing several useful properties:

  • .config – The object used to generate the request.
  • .data – A string or an object that carries the actual response from the server.
  • .headers – A function that can be used to retrieve header information from the response.
  • .status – A number representing the HTTP status code (e.g., 200, 404).
  • .statusText – A string describing the HTTP status (e.g., "OK", "Not Found").

These properties help you manage and handle server responses effectively in your AngularJS application.

Output :

To handle errors, add one more functions to the .then method:
Output :

JSON

The data you get from the response is expected to be in JSON format.

JSON is a great way of transporting data, and it is easy to use within AngularJS, or any other JavaScript.

Example: On the server we have a file that returns a JSON object containing 15 customers, all wrapped in an array called records.

Output :