简体   繁体   中英

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?

Use $http.post method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM