gpt4 book ai didi

AngularJs http 方法覆盖 PUT-POST

转载 作者:行者123 更新时间:2023-12-02 00:04:48 25 4
gpt4 key购买 nike

有没有一种方法可以使用 X-HTTP-Method-Override_method 来使用 Angular 的 $resource 服务覆盖 http 方法> 请求中的参数?

最佳答案

在您的资源工厂中,您可以为每种类型的请求指定方法。

angular.module('myServices', ['ngResource'])
.factory('Customer', function($resource){
return $resource('../api/index.php/customers/:id', {id:'@id'}, {
update: {method:'PUT'}
});
})

是标准方法,但您也可以使用它:

angular.module('myServices', ['ngResource'])
.factory('Customer', function($resource){
return $resource('../api/index.php/customers/:id', {id:'@id'}, {
update: {params: {'_method':'PUT', id: '@id'}}
});
})

关于AngularJs http 方法覆盖 PUT-POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19052431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com