Caleb Prenger
Caleb Prenger

Reputation: 2077

Angular and $http.post()

I'm doing a post in angularjs and realized that my API is not working because angular is saying it's sending data via post, but it's actually all sending as a get

  $http({
        url:'some_url/',
        method:'POST',
        params:{"table":"users", "info":info},
        headers:{'Content-Type':'application/x-www-form-urlencoded'}
    }).success(function(data){
        console.log(data)
    })

The browser tells me its being sent as a post, but the url being sent has all the information in it as a get would

Upvotes: 1

Views: 37

Answers (1)

Patrick Kelleter
Patrick Kelleter

Reputation: 2771

use the "data" parameter, not the "params" parameter. while "params" adds variables to the url, "data" appends it to the body.

  $http({
        url:'some_url/',
        method:'POST',
        data:{"table":"users", "info":info},
        headers:{'Content-Type':'application/x-www-form-urlencoded'}
    }).success(function(data){
        console.log(data)
    })

see also official docs for this: https://docs.angularjs.org/api/ng/service/$http

Upvotes: 1

Related Questions