divya
divya

Reputation: 39

Error while parsing JSON response using $http

[
    {
        "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

Upvotes: 0

Views: 61

Answers (2)

Kaustubh Khare
Kaustubh Khare

Reputation: 3510

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.

Upvotes: 1

ajithes1
ajithes1

Reputation: 427

Use

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

Instead of

$scope.invoice = response.invoiceNo;

Upvotes: 0

Related Questions