1

I am upgrading my site. I upgraded to AngularJS v1.7.6 and JQuery v1.12.1 I get this error message in my console log.

TypeError: Cannot read property 'CustomerId' of undefined

All I did was change .success to .then as .success was depreciated.

Here is the code where I made the change. So I believe data[0] is null so there is no property CustomerId. This function would work with my older version of jquery and angular with the method of .success instead of .then

I am not sure what to do to fix this...(going in circles here)

$scope.sessionDetails = function () {
            urlService.dataProvider(sessionMethod, "POST", '').then(function (data) {
                $scope.sesCustomerId = data[0].CustomerId;
                $scope.sesToken = data[0].Token;
                $scope.sesCustomerName = data[0].CustomerName;
                $scope.sesUserIsMember = data[0].IsMember;
                $scope.userEmail = data[0].Email;

                var indexFavUrl = wLArray.indexOf("Favourites");
                if (wLArray[indexFavUrl] == "Favourites") {
                    if ($scope.sesCustomerId != '') {
                        //Getting User Favourite Items with customer Id
                        $scope.GetFavouriteItems($scope.sesCustomerId);
                    }
                }
                /* To Open Popup after login */
                if (sessionStorage.getItem("CustomPro") == "fromCompse") {
                    if (!sessionStorage.getItem("UMBID")) {
                        var cprt = window.location.search.split("=")[1];
                        var isprodmemonly = window.location.search.split("=")[2];
                    }
                    else {
                        var cprt = sessionStorage.getItem("UMBID");
                        var isprodmemonly = sessionStorage.getItem("UMBID_IsMem") == "true" ? true : false;

                    }
                    show();
                    if ($scope.sesUserIsMember != "1" && isprodmemonly) {
                        jAlert('This Product is only for members.');
                        sessionStorage.removeItem("CustomPro");
                        return false
                    } else {
                        $scope.ProductCompose(cprt, '', cprt, isprodmemonly);
                    }
                }
            });

        }
        $scope.sessionDetails();
Loki Kira
  • 19
  • 4
  • 3
    please console.log data, it may be a response object instead of the actual data – Luca Kiebel Feb 07 '19 at 20:30
  • If response data is empty from `urlService.dataProvider ` `data[0].CustomerId` will cause this error. You need check data[0] exists before set values – aseferov Feb 07 '19 at 20:31

1 Answers1

0

for jQuery you need to replace .success() with .done() and not .then()

cieunteung
  • 1,725
  • 13
  • 16
  • Okay. So replace .success() with .done() and .error() with .fail() . More details can be found here: https://stackoverflow.com/questions/5436327/jquery-deferreds-and-promises-then-vs-done – Loki Kira Feb 08 '19 at 16:04