Shailesh Lobo
Shailesh Lobo

Reputation: 43

Post method in Angular JS

I have following code:

var req = {
    method: 'POST',
    url: '/customer',
    headers: {
      'Content-Type': 'application/json'
    },
    data: { test: 'testvalue' }
};

$http(req).then(function(){
    console.log("f1")
},function(){
    console.log("f2")
});

The code above posts this:

{ '{"test":"testvalue"}': '' }

When I need something like this:

{"test":"testvalue"}

Does any one know the solution to this problem?

Upvotes: 1

Views: 50

Answers (1)

Bob  Sponge
Bob Sponge

Reputation: 4738

Use $http.post method:

$http.post('/customer', { test: 'testvalue' }, {
    headers: {
        'Content-Type': 'application/json'
    }
}).then(function(){
    console.log("f1")
},function(){
    console.log("f2")
});

Upvotes: 1

Related Questions