0
[
    {
        "dueAmount": 400,
        "paidAmount": 0,
        "balanceAmount": 400,
        "invoiceNo": "VA019_203829",
        "planName": null,
        "schemeName": null,
        "connectionStatus": null
    }
]

I'm getting this response from postman. But when i try to read these contents from my page, it returns "Undefined"

$http({ 
method:'POST', 
url: 'http://10.10.1.200:8081/SelfCare/customer/getInvoiceDetails',
headers: { 
            'Content-Type': 'application/json', 
            'Accept': 'application/json'
        }, 
data: JSON.stringify(getID)
       }).then(function (response) { 
        $scope.invoice = response.invoiceNo;
        alert($scope.invoice);
}

its always alerting undefined

4
  • 1
    Try response.data[0].invoiceNo. Your response will be encapsulated into data. Commented Nov 9, 2017 at 6:41
  • 1
    Try console.log(response) in then. It should work with response.data[0].invoiceNo. Commented Nov 9, 2017 at 6:42
  • use console.log than alert. Commented Nov 9, 2017 at 6:43
  • thank you so much... its working... Commented Nov 9, 2017 at 6:45

2 Answers 2

1

You need to do a change replace $scope.invoice = response.invoiceNo; by $scope.invoice = response.data[0].invoiceNo;

Your response will get encapsulated into data.

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

Comments

0

Use

$scope.invoice = response.data[0].invoiceNo;

Instead of

$scope.invoice = response.invoiceNo;

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.