Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用AngularJS将json数据发布到restService_Angularjs_Rest_Spring Mvc - Fatal编程技术网

如何使用AngularJS将json数据发布到restService

如何使用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", ['$

我在头版使用SpringMVC框架和AngularJS。我需要将post JSON数据获取到restservice。从主文件测试和编码的服务一切正常。但问题是,当我尝试使用Angular Js发布数据时,它失败了。请检查一下我的js和jsp文件中列出的数据,并告诉我哪里出错了。我期待着你的帮助

JS文件:

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">