【问题标题】:angular $resource methods dont send the right value角度 $resource 方法不发送正确的值
【发布时间】:2015-01-07 06:44:32
【问题描述】:

这是我的服务

.factory('ProductData', ['$resource', function($resource) {
    return $resource('product/:id', {id: '@id'}, {
        'update': { method:'PUT' },
        'insertNew': { method:'POST' },
        'delete': { method:'DELETE' },
    });
}]);

这是在我的控制器中

$scope.updateProduct = function(item) { 
    var product = ProductData.get({
        id : item.id        
    }, function() {
        product.name = item.name;
        product.description = item.description;
        product.ctg_id = item.ctg_id;
        product.ctgid = item.ctg_id;
        product.$update(item.id);
    });
};

$scope.deleteProduct = function(item) {
    var product = ProductData.get({
        id : item.id
    }, function() {
        product.id = item.id;
        product.$delete(item.id);
    });
};

当我在 WAMP 中工作时,所有方法都运行良好。 但是当我上传到网络服务器时,

GET 请求发送正确的值示例:

http://www.xxx-xxx.com/product/53 

但所有其他方法都发送这个

http://www.xxx-xxx.com/product/53?0=5&1=3

我该如何解决这个问题?

【问题讨论】:

  • 你能提供更多关于你如何使用ProductData的代码吗?
  • 编辑,添加控制器代码

标签: angularjs ngresource


【解决方案1】:

你应该在 $scope.deleteProduct 函数中调用:ProductData.delete(...)

【讨论】:

  • 谢谢!现在请求正在发送正确的值,但仍然为“PUT”和“DELETE”收到 501“方法未实现”,我知道这可能与网络服务器配置有关。我看到我可以用 .htaccess 覆盖它,但还没有弄清楚如何。
猜你喜欢
  • 1970-01-01
  • 2014-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-25
相关资源
最近更新 更多