Phạm Quốc Bảo Phạm Quốc Bảo - 1 year ago 118
AngularJS Question

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":"","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

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

Answer Source

Yes there is no success property inside the JSON .

Change it as,

if(providerObj) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download