【问题标题】:POST Behavior Between $http and Restangular$http 和 Restangular 之间的 POST 行为
【发布时间】:2013-12-18 00:27:09
【问题描述】:

我有一个简单的 ASP.NET Web API 2 服务。我是 Angular 的新手,但我正在尝试从使用 $http 切换到 Restangular。我的 GET 似乎很好,但我的 POST 不是。

代码如下:

    $scope.addLift = function () {
    $http.post(url, $scope.Lift);
    //Restangular.all('lifts').post('Lift', $scope.Lift).then(function (newLift) {
    //    $scope.getLifts();
    //}, function (error) {
    //    console.log(error);
    //});
};

注释掉的 Restangular 代码不起作用,但 $http.post 起作用,我不确定自己做错了什么。

如果有帮助的话,使用 Restangular 时的 POST 是 http://localhost/api/lifts?LiftName=test$http POST 请求中,它不包含 URL 行上的参数,似乎数据在请求正文中。

【问题讨论】:

    标签: angularjs restangular


    【解决方案1】:

    另一个网站上的某个人很友善地帮助我解决了这个问题。以为我会发布答案,希望对其他人有所帮助。

    Restangular.all('lifts').post($scope.Lift).then(function (newLift) {
            $scope.getLifts();
        }, function (error) {
            console.log(error);
        });
    

    post 调用中不需要额外的 'lift' 参数。

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 2015-01-01
      • 2016-04-22
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多