AngularJS HTTP POST Request

How to send data through AngularJS as a post request.

by Nathaniel Anderson

HTML

<div ng-app="myControllers">


<div ng-controller="FormController">
Notes:<br />
Must include $httpParamSerializerJQLike<br />
Must send headers: Content-Type = application/x-www-form-urlencoded<br />
Must use $httpParamSerializerJQLike to serialize the data you're sending through the POST Request
<p>
{{ s({name:'All ; ist good'}) }}
</p>
</div>
</div>

JavaScript

//https://stackoverflow.com/questions/42075080/unknown-provider-httpparamserializerjqlikeprovider-httpparamserializerjqli
var myControllers = angular.module( 'myControllers', [] );
myControllers.controller( 'FormController', function( $scope, $http, $httpParamSerializerJQLike ) {
	$scope.master = {};
	
  $scope.s =  $httpParamSerializerJQLike;
  
	$scope.update = function( user ) {
		$scope.master = angular.copy( user );
		console.log( $scope.master );
	
		$http( {
			method: 'POST',
			url: 'test.php',
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $httpParamSerializerJQLike({
				'name': user.name,
				'email': user.email,
				'gender': user.gender
			})
		} ).success( function( data ) { console.log( data ); } );
	}
	
	$scope.reset = function() {
		$scope.user = {};
		$scope.master = {};
	}
} );