如何使用AngularJS将json数据发布到restService
我在头版使用SpringMVC框架和AngularJS。我需要将post JSON数据获取到restservice。从主文件测试和编码的服务一切正常。但问题是,当我尝试使用Angular Js发布数据时,它失败了。请检查一下我的js和jsp文件中列出的数据,并告诉我哪里出错了。我期待着你的帮助 JS文件:如何使用AngularJS将json数据发布到restService,angularjs,rest,spring-mvc,Angularjs,Rest,Spring Mvc,我在头版使用SpringMVC框架和AngularJS。我需要将post JSON数据获取到restservice。从主文件测试和编码的服务一切正常。但问题是,当我尝试使用Angular Js发布数据时,它失败了。请检查一下我的js和jsp文件中列出的数据,并告诉我哪里出错了。我期待着你的帮助 JS文件: var helloAjaxApp = angular.module("helloAjaxApp", []); helloAjaxApp.controller("ItemsCtrl", ['$
var helloAjaxApp = angular.module("helloAjaxApp", []);
helloAjaxApp.controller("ItemsCtrl", ['$scope', '$http', function($scope, $http) {
$scope.item = [
{ 'name':'burger',
'price': 1.99},
];
$scope.addRowAsyncAsJSON = function(){
$scope.companies.push({ 'name':$scope.name, 'price': $scope.price});
// Writing it to the server
//
var dataObj = {
name : $scope.name,
price : $scope.price
};
var res = $http.post('/item', dataObj);
res.success(function(data, status, headers, config) {
alert('going to other method 5' );
$scope.message = data;
});
alert('going to other method 4' );
res.error(function(data, status, headers, config) {
alert( "failure message: " + JSON.stringify({data: data}));
});
$scope.name='';
$scope.price='';
};
}]);
列出数据结果的JSP:
<div ng-controller="item">
<p>The ID is {{item}}</p>
<p>The content is {{item.id}}</p>
</div>
乍一看像
<div ng-controller="item">
应该是
<div ng-controller="ItemsCtrl">