加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – angular.js $http.post不工作?? – 没有错误

发布时间:2020-12-17 08:06:28 所属栏目:安全 来源:网络整理
导读:我试图使用$ http提交一个新的评论。你可能已经从标题中猜到了:它不工作。我尝试了岸版和长版,都失败了。没有控制台错误。 这是我的代码: $scope.comment = {};$scope.comment["comment"] = message; // message defined somewhere else$http.post('/api/
我试图使用$ http提交一个新的评论。你可能已经从标题中猜到了:它不工作。我尝试了岸版和长版,都失败了。没有控制台错误。

这是我的代码:

$scope.comment = {};
$scope.comment["comment"] = message; // message defined somewhere else

$http.post('/api/items/'+$scope.item.id+'/comments',$scope.comment)
    .success(function(data,status,headers,config) {
         // this isn't happening:
         console.debug("saved comment",$scope.comment);
    })
    .error(function(data,$scope.comment);
    })
}

任何人有什么想法如何使这项工作?谢谢!

更新:

我正在做一个Jquery ajax调用,这是正常工作。这是很高兴得到它有角度工作。这是我的JQuery代码:

var request = $.ajax({
                url: '/api/items/'+$scope.item.id+'/comments',type: "POST",data: JSON.stringify($scope.comment),contentType: 'application/json; charset=utf-8',dataType: "json"
            });

            request.done(function(msg) {
                console.debug("saved comment",$scope.comment);
            });

            request.fail(function(jqXHR,textStatus) {
                alert( "Request failed: " + textStatus );
            });

如果有任何人有任何想法如何变形,请告诉我,将是很好的做到正确的方式….

在提出请求之前是否曾试过专门设置Content-Type?

我有同样的问题,并设置Content-Type修复它。

$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读