rest - AngularJS DELETE with Tomcat causes 405 Request method 'DELETE' not supported -
i'm using spring data neo4j rest backend served on tomcat (8.0.27) angular frontend, served locally @ http://localhost:8080/. when try delete record either $http.delete() or $resource().delete(), tomcat returns 405 not supported error.
however, using $http({method: 'delete', url: '/competitors/13'}) works fine. unfortunately, not allow me use angular $resource service instead of $http, goal. (as aside, put creates same 405 response delete)
i able use delete command line. works fine:
curl -x delete http://localhost:8080/competitors/13
i have disable csrf in websecurityconfig in case has it.
i have added readonly init-param web.xml try force tomcat accept delete, so:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>proto v2 application</display-name> <servlet> <servlet-name>proto</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>readonly</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>proto</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
since i've verified server able perform delete, omit java code. here complete .js file angular module:
var magneticapp = angular.module('magneticapp', ['ngresource']) .controller('defaultctrl', function ($scope, $http, $resource, baseurl) { $scope.competitor = $resource("/competitors/:id", {id: "@id"}); $scope.listitems = function () { var query = $scope.competitor.get(function () { console.log('inside query'); }); query.$promise.then( function successcallback(data) { $scope.competitors = data._embedded.competitors; }, function errorcallback(data) { console.log('error:'); console.dir(data); } ); }; /* * delete function returns 405 not supported error */ $scope.deleteitem = function (item) { var query = $scope.competitor.delete({}, item.itemid); query.$promise.then( function successcallback(data) { console.log('success:'); $scope.competitors.splice($scope.competitors.indexof(item), 1); }, function errorcallback(data) { console.log('error:'); console.dir(data); } ); }; /* * delete function works */ $scope.deleteitemworkscorrectly = function (item) { $http({method: 'delete', url: '/competitors/' + item.itemid}) .then( function successcallback(data) { $scope.competitors.splice($scope.competitors.indexof(item), 1); }, function errorcallback(data) { console.log('delete error'); console.dir(data); } ); }; $scope.adjustactive = function (item) { item.id = item.itemid; console.log('adjustactive'); console.dir(item); $http.post('/competitors', item) .success(function (data) { $http.get('/competitors').success(function (data) { console.dir(data._embedded.competitors); $scope.competitors = data._embedded.competitors; }); }); }; $scope.additem = function (itemname) { var item = {name: itemname}; $http.post('/competitors', item) .success(function (data) { $http.get('/competitors').success(function (data) { console.dir(data._embedded.competitors); $scope.competitors = data._embedded.competitors; //magneticapp.controller('defaultctrl').$scope.competitors = data._embedded.competitors; }); }); }; $scope.listitems(); });
can shed light on this? thanks.
Comments
Post a Comment