Skip to content

Instantly share code, notes, and snippets.

@aquasmit
Created December 19, 2016 04:22
Show Gist options
  • Save aquasmit/724d3159cf2789db83c0119fd78ffe7d to your computer and use it in GitHub Desktop.
Save aquasmit/724d3159cf2789db83c0119fd78ffe7d to your computer and use it in GitHub Desktop.
AngularJs - send data with $http.post()

Send data with $http.post() in AngularJs

In AngularJs Controller

....
  var config = {
      headers : {
          'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
      }
  }
  $http.post('http://5.project/posts',{category_id:11},config)
  .then(function(response) {	
      vm.posts = response.data;
  });              

And to receive above category_id in php, we have to use following:

....
$params = json_decode(file_get_contents('php://input'),true);
print_r($params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment