2016-04-27 123 views
2

當我使用下面的代碼發出請求我的C#方法沒有得到任何數據:

$http({ 
    method : 'POST', 
    url : ..., 
    data : { 
     test : 'hello' 
    }) 
    .then(function (result) { 
     console.log('success') 
    }, function() { 
     console.log('error') 
    }) 

在調試模式下,我能夠打的方法,但沒有數據與傳遞請求。

+3

顯示你的C#方法請 –

+0

嘗試'數據:JSON.Stringify( {test:'hello'})'。什麼是測試/ –

回答

2

這是一個常見的錯誤。您的電話應該是這樣的:

$http({ method: 'POST', 
     url: ..., 
     data: $httpParamSerializerJQLike({ test: 'hello' }), 
     headers: { 'Content-Type': 'application/x-www-form-urlencoded' } 
) 
.then(function() { console.log('success') }, 
     function() { console.log('error') }) 

也別忘了深入的解釋注入$httpParamSerializerJQLike

更多 - >AngularJs $http.post() does not send data

+1

常見的錯誤是什麼?缺少標題? – Marco

+0

什麼部分數據是'application/x-www-form-urlencoded'? –