【发布时间】:2014-02-13 22:40:56
【问题描述】:
我使用grails 2.3.4 作为我的angularjs 1.2.8 应用程序的后端。
我想将我的数据保存到数据库中。我试图这样实现它:
testApp.controller('testController', function($scope, $rootScope, $http, $location) {
$scope.product = {};
$scope.saveProduct = function() {
console.log('call saveProduct');
$http
.post($rootScope.appUrl + '/product.json', $scope.book)
.success(function(data, status, headers, config) {
$location.path('/product');
}).error(function(data, status, headers, config) {
});
}
});
原则上这应该可行,因为我的后端使用@Resource(uri='/product') 来提供 RESTFUL API。我可以这样称呼所有现有产品:http://localhost:8080/testApplication/product.json
但是 chrome 控制台诊断给了我:
POST http://localhost:8080/testApplication/undefined/product.json 404 (Not Found)
undefined 使此链接失效。有什么建议可以去掉吗?
关于如何更改我的功能以使其正常工作的任何建议?
【问题讨论】:
标签: javascript json angularjs grails grails-2.0