1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.