angularjsangularjs-scopeangular-data

Angular $http post returning empty data


I'm managing to post to the server OK, I'd like to get the updated data and load it back into the same JSON object, but the data response is null.

$scope.saveDetails = function() {
    $http({
        method : 'POST',
        url : '/service/rest/orders',
        data : $scope.orderDetails
    })
    .success(function(data, status) {
        $scope.orderDetails = data;                 
    })
    .error(function() {
        alert('error');
    });                  
}

Also worth mentioning, that the initial object is being passed from another controller via $rootscope and injected into the local scope.

$scope.orderDetails = $rootScope.newOrder;

Thanks for any help.


Solution

  • Your code looks fine, I would be checking the backend to make sure data is actually being sent. Another option would be to use the chrome inspector and check the response to make sure you are actually getting something back.