javascript - 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();
解决方案
对于 jQuery,您需要替换.success()
为.done()
而不是.then()
推荐阅读
- python - 使用 Github 操作构建带有“CBUILDWHEEL”的 Python/C++ pybind11 包时出现问题?
- javascript - P5JS - 画布内容比例错误
- postgresql - Repmgr SSH 用户
- apache-beam - 使用 python 根据 apache Beam 中的条件调用特定的 pubsub 主题
- php - 如何在表php中获取单行数据
- autocad - AutoCAD 错误。“绘图文件无效。”
- python - 无法在 OpenCV Python 中第二次加载相机
- pymongo - 我怎样才能很好地更新 pymongo 上的数据?
- ruby-on-rails - Rails and Devise:成功登录后如何将用户重定向回请求的页面?
- excel - 许多工作表宏的 Excel 副本