我有一个 Angular 应用程序,应该与 json-server 一起使用来检索数据并添加新数据(用户反馈)。所以我有 json 数据库和一些数组,其中之一是"feedbacks":[]
目前是空的。在 PUT 方法上我得到:
PUT /feedbacks 404
来自服务器,这是 chrome 控制台PUT http://localhost:3000/feedbacks 404 (Not Found)
.
这是我的服务:
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'
}
});
};
}]);
这是控制器:
// 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()
方法有效,服务器发送 200,但对于 PUT,我收到 404。