Angular $ PUT method cannot make it work

I am using a REST api, and I would like to update my project objects with a PUT request. The request is supported in the API, and I'm trying to use $ resource for PUT data, but it does not seem to work. That's what I'm doing:

var projectResource = $resource('/api/projects/' + projectId, {update: {method: "PUT"}}); $scope.editProject = function(editedProject) { projectResource.$update(editedProject); } 

If editProject is a project with new values, filled out a form on a web page. I know that something is wrong in my projectResource declaration, but I do not find that. Help!

+4
source share
2 answers

Try the following:

 $resource('/api/projects', { id: projectId }, { update: { method: 'PUT' } }); 
+14
source

$ resource cannot use the "PUT" method, due to the lack of "Access-Control-Allow-Origin". You can find "OPTIONS" on the networks. In this case, you need to create your PUT call:

 var data = $resource('someURL', { jobId: '@jobId'}, { 'update': { method:'PUT' }}); data.update(objectYouWannaUpdate); 
0
source

Source: https://habr.com/ru/post/1485971/


All Articles