【问题标题】:Angular js - The URL for PUT request to service not been addedAngular js - 未添加 PUT 服务请求的 URL
【发布时间】:2016-09-09 04:57:05
【问题描述】:

这是我的脚本:

var shipResource = $resource('http://localhost\\:8083/consignments/:cId', null, {ship: {method: 'PUT'}});

$scope.shipConsignment = function() {
   if($scope.selectedConsignment != null){
        var consignId = $scope.selectedConsignment.consignmentId;
        console.log(consignId) //works fine
       shipResource.ship({cId: "consignId"}); //not working? cId is not added to URL
    }
};

还有 HTML:

<button type="button" ng-click="shipConsignment()">Ship</button>

一个服务端我有一个PUT请求URL的功能:localhost:8083/consignment/{consignmentId}。

但是请求被发送到 localhost:8083/consignment。这给了我 405 方法不允许。任何帮助将不胜感激。

【问题讨论】:

  • 如果我更改方法:'GET' 它会将 consinId 添加到 url 但不是 PUT。
  • 我发现这是一个 CORS 问题

标签: javascript java html angularjs rest


【解决方案1】:

然后试试这个:

$resource('http://localhost\\:8083/consignments/:id', {Id: "@cId"}, {ship: {method: 'PUT'}});

【讨论】:

    猜你喜欢
    • 2014-10-07
    • 1970-01-01
    • 2018-02-15
    • 2015-11-11
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多