2016-04-27 115 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'? –