首页 > 解决方案 > TypeError:无法读取未定义的属性“CustomerId”

问题描述

我正在升级我的网站。我升级到 AngularJS v1.7.6 和 JQuery v1.12.1 我在控制台日志中收到此错误消息。

TypeError: Cannot read property 'CustomerId' of undefined

我所做的只是将 .success 更改为 .then,因为 .success 已贬值。

这是我进行更改的代码。所以我相信 data[0] 是空的,所以没有属性 CustomerId。此功能适用于我的旧版本 jquery 和 angular 使用 .success 而不是 .then 的方法

我不知道该怎么做才能解决这个问题......(在这里转圈)

$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();

标签: javascriptjqueryangularjs

解决方案


对于 jQuery,您需要替换.success().done()而不是.then()


推荐阅读