I am using Spring MVC framework and using AngularJs in the front page. I need to get post JSON Data to restservice. Everything works fine with the service that tests and coding from main file is fine. But the problem is when I try to post data by using Angular Js it fails. Could you please check my js and jsp file where data is listed and tell me where I make mistake . I am looking forward for your helps.
Regards Alper Kopuz
JS File :
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 where data result is listed:
<div ng-controller="item">
<p>The ID is {{item}}</p>
<p>The content is {{item.id}}</p>
</div>