Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I have an angular app that supposed to work with json-server for retrieving data and adding new data (users feedback). so I have json database with some arrays and one of them is "feedbacks":[] which is currently empty. on PUT method I get:

PUT /feedbacks 404 from server and this is chrome console PUT http://localhost:3000/feedbacks 404 (Not Found).

this is my service:

angular.module('myApp')
        .constant("baseURL", "http://localhost:3000/")
.service('feedbackService',['$resource','baseURL',function($resource,baseURL){
      this.getFeedback=function(){
        return $resource(baseURL+"feedbacks/:date",null,{
          'update':{
            method:'PUT'
          }
        });
      };
    }]);

this is the controller:

    // contactus.html controllers
.controller('ContactController', ['$scope', function($scope) {
            $scope.feedback = {firstName: "",lastName: "",email: "",date: ""};
        }])
        // Feedback form controller
        .controller('FeedbackController', ['$scope', 'feedbackService', function($scope, feedbackService) {
            $scope.feedbacks = feedbackService.getFeedback().query(function(response) {
                $scope.feedbacks = response;
            });
            $scope.sendFeedback = function() {
                    $scope.feedback.date = new Date().toISOString();
                    $scope.feedbacks.push($scope.feedback);
                    feedbackService.getFeedback().update($scope.feedbacks);
                    $scope.feedbackForm.$setPristine();
                    $scope.feedback = {firstName: "",lastName: "",email: "", date:""};
            };
        }])

getFeedbacks() method works and server send 200, but for PUT I receive 404.

share|improve this question
    
You have to check for your service layer. Nothing to do here in front end. – ramamoorthy_villi Aug 20 at 12:14
    
@ramamoorthy_villi I am new to this, what should I check in service Layer? – AmirHM Aug 20 at 12:16
    
check the put method working in server part – ramamoorthy_villi Aug 20 at 12:25
    
@ramamoorthy_villi yes PUT method works, cause I have another controller for commenting and there PUT works perfectly – AmirHM Aug 20 at 12:29

OK I solved it :)) a very silly mistake. there was no need for push and then update as I wanted to create new object inside the array.

$scope.feedback.date = new Date().toISOString();
feedbackService.getFeedback().save($scope.feedback);

and also I changed the service to:

return $resource(baseURL+"feedbacks/:id",null,{

to have auto incremental id for each object

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.