4

I use a REST api and I'd like to update on of my project objects with a PUT request. The request is supported in the API, and I'm trying to use $resource to PUT the data, but it doesn't seem to work. Here is what I do :

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

Where editedProject is the project with the new values, filled by a form in a webpage. I know there is something wrong in my projectResource declaration, but I don't find what. Help !

4

2 回答 2

14

尝试这个:

$resource('/api/projects', { id: projectId }, {
    update: { method: 'PUT' }
});
于 2013-06-13T10:11:35.367 回答
0

$resource 无法制作“PUT”方法,因为没有“Access-Control-Allow-Origin”。您只能在网络中找到“选项”。在这种情况下,您需要创建 PUT 调用:

var data = $resource('someURL', { jobId: '@jobId'}, { 'update': { method:'PUT' }});
data.update(objectYouWannaUpdate);
于 2016-11-17T03:34:21.240 回答