0

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.

5
  • Does it hits the url Commented Apr 15, 2015 at 5:14
  • Where did u call this method saveDetails Commented Apr 15, 2015 at 5:16
  • Once try this.... data : {$scope.orderDetails}, headers:{'Content-Type':'application/x-www-form-urlencoded'} Commented Apr 15, 2015 at 5:53
  • I think it should be $http({ method : 'POST', url : '/service/rest/orders', data : {orderDetails: $scope.orderDetails} }) order details is parameter on server side Commented Apr 15, 2015 at 5:55
  • Thanks for your replies everyone, turns out it was returning the whole object, so the top level. Commented Apr 15, 2015 at 6:15

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This should be a comment
Thanks for your reply Ryan, I thought I'd checked, but I rechecked again after you said this and it turns out it was returning data. Thanks!
0

It turns out it was returning the whole object and the order was deeper down, I didn't see that in my console at first.

$scope.orderDetails = data.order;  

Thanks for all replies.

Comments

0

In case anyone else runs into this, in my case I had a class with a data contract attribute applied:

[DataContract(Namespace = "http://somespace.com")]

And my class members had not been given the [DataMember] attribute. Web API was not returning back the data. I added the [DataMember] attribute and it fixed it.

[DataMember] public int NumberUpdated { get; set; }
[DataMember] public int NumberInserted { get; set; }
[DataMember] public List<ServicesListImport> InvalidRows {get; set;}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.