2016-02-08 52 views
1

我有以下代碼:Post方法在角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") 
}); 

上述職位本的代碼:

{ '{ 「測試」: 「測試值」}': ''}

當我需要的是這樣的:

{ 「測試」:「名爲testVal ue「}

有沒有人知道這個問題的解決方案?

+0

我會嘗試像VAR測試= 「測試值」;然後數據:test –

回答

1

使用$http.post方法:

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

這給出了相同的錯誤輸出{'{「test」:「testvalue」}':''} –