簡體   English   中英

Angular JS中的Post方法

[英]Post method in Angular JS

我有以下代碼:

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”}':''}

當我需要這樣的東西:

{ “測試”: “測試值”}

有誰知道解決這個問題的辦法嗎?

使用$http.post方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM