簡體   English   中英

在AngularJS中獲取405(不允許使用方法)

[英]Getting a 405 (Method Not Allowed) in AngularJS

因此,我正在創建一個Web應用程序,其中一個頁面上有一個用戶列表,第二個頁面上有一個用戶詳細信息頁面。 在第二頁上,當單擊帶有200狀態代碼的“確認”按鈕時,我想在其中刪除該用戶。 但是,我得到了DELETE : 405 (Method Not Allowed) 因此,這是下面的代碼。 請告訴我或幫助我解決此問題。 先感謝您。

這是我的代碼。

<div ng-controller="MyCtrl">
  <div ng-repeat="person in userInfo.lawyers | filter : {id: lawyerId}">

    <a class="back" href="#/lawyer">Back</a>

    <button type="button" class="edit" ng-show="inactive" ng-click="inactive = !inactive">
      Edit
    </button>

    <button type="submit" class="submit" ng-show="!inactive" ng-click="inactive = !inactive">Save</button>



    <button class="btn btn-primary" ng-click="doDelete(id)">Confirm</button>



    <div class="people-view">

      <h2 class="name">{{person.firstName}}</h2>

      <h2 class="name">{{person.lastName}}</h2>

      <span class="title">{{person.email}}</span>

      <span class="date">{{person.website}} </span>


    </div>

    <div class="list-view">

      <form>

        <fieldset ng-disabled="inactive">

          <legend>Basic Info</legend>

          <b>First Name:</b>

          <input type="text" ng-model="person.firstName">
          <br>

          <b>Last Name:</b>

          <input type="text" ng-model="person.lastName">
          <br>

          <b>Email:</b>

          <input type="email" ng-model="person.email">


        </fieldset>

      </form>

    </div>
  </div>
</div> 

服務

    app.factory('people', function ($http) {
    var service = {};
    service.getUserInfo = function () {
        return $http.get('https://api-dev.mysite.io/admin/v1/unconfirmed_lawyers');
    };

    service.confirmUser = function (lawyerId) {
        return $http.put('https://api-dev.mysite.io/admin/v1/lawyers/{lawyerId}/confirm');


    };

    return service;


});

LawyerController

    app.controller('LawyerController', ['$scope', 'people', '$routeParams',
    function ($scope, people, $routeParams) {


        $scope.lawyerId = $routeParams.id;
        people.getUserInfo().then(function (response) {
            $scope.userInfo = response.data;
        });




    }]); 

HomeController的

    var isConfirmed = false;
app.controller('HomeController', function($scope, people, $http) {
    if (!isConfirmed) {
        people.getUserInfo().then(function (response) {

            $scope.userInfo = response.data;



        }, function (error) {
            console.log(error)
        });
    }
}); 

App.js

    $scope.doDelete = function(lawyer) {
        var index = $scope.userInfo.lawyers.indexOf(lawyer);
        $scope.userInfo.lawyers.splice(index, 1);
        location.href = '#/lawyer';
    };

如果您更改了HTML,則改為通過此人。

<button class="btn btn-primary" ng-click="doDelete(person)">Confirm</button>

您可以使用它在律師中找到索引,然后將其刪除。

$scope.doDelete = function(lawyer) {
    var index = $scope.userInfo.lawyers.indexOf(lawyer);
    $scope.userInfo.lawyers.splice(index, 1)
};

問題是您正在使用執行HTTP刪除請求的$http.delete 這聽起來不像您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM