0
因此,我正在創建一個Web應用程序,其中一個頁面有一個用戶列表,另一個頁面上有我的用戶詳細信息頁面。在第二頁上,我有一個確認按鈕,當用「200狀態」代碼單擊「確認」按鈕時,我想刪除該用戶。但是,我得到一個DELETE : 405 (Method Not Allowed)
。所以,下面是我的代碼。請告訴我或幫我解決這個問題。先謝謝你。在AngularJS中獲得405(方法不允許)
這是我的代碼。
<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';
};
這是正確的嗎?在你的MyCtrl中的$ scope.doDelete func中使用'$ http.delete(location.href + id)'?您要將該ID附加到當前URL的末尾,並使用HTTP DELETE – user2340824
yes。基本上,要從「home.html」中的列表中刪除該用戶 –
您是否創建了API以支持HTTP DELETE方法?這可能是光顧,但是你打算永久刪除此用戶還是僅僅在此視圖中刪除?例如如果您要刷新頁面,您是否期望用戶再次可見? – user2340824