我有以下代码:
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")
});
上面的代码发布了这个:
{ '{"test":"testvalue"}': '' }
当我需要这样的东西时:
{"test":"testvalue"}
有人知道这个问题的解决办法吗?
最佳答案
使用$http.post
方法:
$http.post('/customer', { test: 'testvalue' }, {
headers: {
'Content-Type': 'application/json'
}
}).then(function(){
console.log("f1")
},function(){
console.log("f2")
});
关于javascript - Angular JS 中的 Post 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35270897/