Phạm Quốc Bảo
Phạm Quốc Bảo

Reputation: 894

AngularJS: JSON.parse(data).success is not defined

I'm trying to use JSON.parse the data:[{"id":"ABC123","provider_type":"Center","name":"Test1","phone":"03 2222 9999","mobile":"1111 123 123","email":"[email protected]","address":["3999, Victoria","Est Danvale","113 HD streed","Block D, K House."]}]

and code:

var callBackProviderSuccess = function(data){
        var providerObj = JSON.parse(data);
        if(providerObj.success) {
            $scope.providerInfo = providerObj.provider;
            $localStorage.providerJPayInfos = $scope.providerInfo;                IBMService.getStaffsOfProvider(providerID).then(callBackStaffsSuccess,callBackStaffsError);

        } else {
            $scope.infoLoadingText = "Provider not found on our database";
            //try again
            IBMService.getProviderById(providerID).then(callBackProviderSuccess,callBackProviderError);
        }  
    };

when debugging at if(providerObj.success), i have a message: providerObj.success undefined. Please help me give your thoughts. Thanks

Upvotes: 0

Views: 110

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

Yes there is no success property inside the JSON .

Change it as,

if(providerObj) {

Upvotes: 2

Related Questions