POSTing Nested JSON in AngularJS [400 error] -
part of html
<div>house details: <input type ="number" ng-model="house.totalarea" placeholder="total_area"> <input type="number" ng-model="house.cost" placeholder="cost"> </div> <div>address: <input type="text" ng-model="house.address.state" placeholder="state"> <input type="text" ng-model="house.address.city" placeholder="city "> </div>
angular:$scope.house = {}; $scope.house.address = {}; $scope.processrentform = function () { console.log($scope.house); $http.post("http://localhost:8080/property101/house/addhouse", $scope). error(function (data, status, headers, config) {alert("submit failed!!");
code works fine $scope.house but
i'm getting 400 eror ( syntactically incorrect) nested json forming
object {address: object, totalarea: 1000}
i have address class inside house class on server side have similar no./names of parameters json i'm trying send.
some of examples @ have "house.address.state" syntax. i'm new angular, appreciated.
before sending request json onto server side following 2 steps,
1) var reqobj = json.stringify($scope.house);
2) var requestjson = json.parse(reqobj)
now send requestjson request. should work.
Comments
Post a Comment