Angularjs Http Post Method


Angularjs Http Post Method : Angularjs Http Post is used to perform post request. It posts data using post method. This method is preferred when you are working with the data which is more secure or you are sending large data. We are going to explain post method with the example and demo.


Angularjs Http Post Method Syntax | Config | Example | Demo

Syntax for Post method –

Angularjs $http.post Syntax:

Parameters

  • url : Thet Url from where you want to load data.
  • data : data you want to post.
  • config(optional): This is optional configuration object .
  • Callback : Callback function after success. Returns object.

Returns

  • Returns : HttpPromise Object.

Angularjs Http Post Method : Php File

Here we are using php at server side to save data. We will post data on the postUsers.php file and save it in table.

Angularjs $http.post Example :

Here is an example of post method in which we are posting posting data using post method. To see the output of the example click on “try it” button –

Angularjs $http.post example with parameters | JSON

Try it ยป

Note : On server side we have used php. You can use your own platform on server side.

The above example will produce the following output of the form to view full functionality click on “Try it” button and fill form and submit to post and see result –

Angularjs Http Post Method

Angularjs Http Post Method Example

Angularjs $http post multiple parameters –

If you want to send the multiple parameters using $http post method you can pass multiple parameters as below –


More About $http Post Method

Let’s have look over more about $http post method.


Headers

The $http service automatically adds some HTTP headers to each requests. You can configure the default headers by accessing the $httpProvider.defaults.headers configuration object. $httpProvider.defaults.headers contains the current header configuration.

  • $httpProvider.defaults.headers.common (Common Headers for all requests):


  • $httpProvider.defaults.headers.post: ( Default Headers for POST requests)


  • $httpProvider.defaults.headers.put (Default Headers for PUT requests)

  • You can add or overwrite the defaults simply adding a new object with the lowercase HTTP method name as the key, e.g. $httpProvider.defaults.headers.get = { ‘Test-Header’ : ‘value’ }.

    Angularjs http post set Header-

    You can set content type header in angularjs $http post method simply as below –

    Angularjs Set http post content type json-

    Angularjs Set http post content type json Example :

    Try Video Demo – All In One Video for this method –

    AngularJs Http Post Method Video Demo –