无法获得$ http响应

杰克编码员

当我使用下面的代码发出请求时,我的C#方法未获得任何数据:

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

在调试模式下,我可以执行该方法,但是没有数据与请求一起传递。

克里斯·赫尔穆特(Chris Hermut)

这是一个常见的错误。您的通话应如下所示:

$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()不发送数据

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章