10
我正在使用djang-tastypie作爲後端,AngularJs用於前端。我正在使用angularjs $ http向CRUD發送請求。 GET,POST,PUT一切正常,但是當我嘗試發送PATCH請求時,出現錯誤Method PATCH未定義。我創建了一個api調用的工廠,但PATCH請求在那裏不起作用。使用angularjs修補請求
angular.module('tastypieModule', ['ngResource']).
factory('apiCall', function($http, $resource) {
delete $http.defaults.headers.common['X-Requested-With'];
var apiCall = $resource('/api/v1/:type/:id/',
{type: '@type', username: '@userName', api_key: '@api_key', user: '@userID', id: '@id'},
{
get: {method: 'GET'},
post: {method: 'POST', headers: {'Content-Type': 'application/json'}},
del: {method: 'DELETE', headers: {'Content-Type': 'application/json'}},
update: {method: 'PUT', headers: {'Content-Type': 'application/json'}},
pupdate:{method:'PATCH',headers: {'Content-Type': 'application/json'}}
}
);
return apiCall;
});
function MyCtrl($scope,$resource){
$scope.edit=function(){
id=$scope.E_id
$http.pupdate('/api/v1/quizsetting/'+id+'/', editedquizsetting).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.editQuizSettingModal = false;
//$scope.quizsettinglist.objects[$scope.e_quizsettingindex]=data;
$(".message").append("object has been created successfully");
})
.
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
}
這是我的HTML代碼
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<button type="button" ng-click="edit()">Edit</button>
</div></div>
當我將在控制檯中使用此代碼路徑請求它顯示http.patch不是一個函數。 告訴我如何配置ng-app和服務以使用angularjs發送PATCH請求。
的[配置angularjs模塊發送補丁請求]可能重複(http://stackoverflow.com/questions/20305615/configure-angularjs-module -to-發送貼片請求) – kynan