user2700574 February 2016

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?

Answers


Bob Sponge February 2016

Use $http.post method:

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

Post Status

Asked in February 2016
Viewed 2,820 times
Voted 13
Answered 1 times

Search




Leave an answer