1

I am trying to get values from json in Angularjs 1.5.But i am getting "undefined"

function getData() {
  $http.get("processRequest.jsp?requestType=getRecords&page=1& limit=20").then(function(response) {
    $scope.totalItems = response.data.ordersCount
    alert(response.data.ordersCount)
  }); 

JSON values

 [{"ordersCount":"100"},{"records":{"MON_FE_ACCNO":"100001810035","MON_FE_CUSTID":"1007","MON_FE_CUSTNAME":"RajKumar","MON_FE_EXEEDING_AMT":"180000"}}]

EDITED:

If i will use $scope.totalItems = response.data[0].ordersCount working fine.why i can't get $scope.totalItems = response.data.ordersCount

Please suggested to me, Where is my mistake?

1 Answer 1

1

since this is an array you need to access 0th position

 $scope.totalItems = response.data[0].ordersCount
Sign up to request clarification or add additional context in comments.

10 Comments

You could also rearrange your JSON and use ordersCount as key.
Thanks sir. @sachila ranawaka
@j.Doe no problem :D
Thanks for your suggestion @getjackx
@j.Doe make sure to mark as right answer if this helped :D
|

Your Answer

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