gpt4 book ai didi

javascript - Angular HttpPost 在 REST 中执行两次

转载 作者:行者123 更新时间:2023-11-28 05:36:06 24 4
gpt4 key购买 nike

$HttpPost 与 Angular 有一些问题,执行两次。供您引用,该函数在从“getActiveSpools()”函数返回 promise 后执行。不知何故,“http://testserver/LitzMobileListener/LitzScannerService.svc/PostMfgoSetup/ ”运行了两次,导致数据上传了两次。

我是 Angular 和 REST 新手。

非常感谢您的帮助

$scope.getActiveSpools().then(function (promise) {

$scope.spoolSetupHeader.STATUS = status;
$scope.spoolSetupHeader.OPTR_IN = $rootScope.globals.currentUser.employeeId;
$scope.spoolSetupHeader.PLANT_NO = $scope.spoolSetupHeader.setupMfgo.substring(1, 2);
$scope.spoolSetupHeader.MFGO_NO = $scope.spoolSetupHeader.setupMfgo.substring(2, 9);

$http({
url: "http://testserver/LitzMobileListener/LitzScannerService.svc/PostMfgoSetup/"
, method: "POST"
, data: JSON.stringify($scope.spoolSetupHeader)
, dataType: "json"
, contentType: "application/json; charset=utf-8",
}).then(function (result) {

$scope.returnedStatus = new ReturnedOperationStatus();
$scope.returnedStatus.IsSuccess = result.data.IsSuccess;
$scope.returnedStatus.Message = result.data.Message;
$scope.spoolSetupHeader = new OrderHeader();//new SpoolSetupHeader();
$scope.spoolSetupHeader.PO_ID = result.data.RecordKey;
$scope.spoolSetupHeader.ReturnedInfo = result.data.ReturnedObject;

if ($scope.returnedStatus.IsSuccess == true) {
alertTitle = "Success";

//upload source wire if needed
if ($scope.swNeeded == true) {

$scope.uploadMfgoSetupSpools('NEW', 'Active', true);
}
else {
$scope.uploadMfgoSetupSpools('UPDATE', 'Inactive', false);
}

//reload saved data
$scope.getSetupMfgo($scope.spoolSetupHeader.PO_ID, 'DETAILS_ACT', null, null);

//init new spool details list
//$scope.spoolSetupHeader.setupSpools = new Array();
//myNavigator.pushPage('partial-setupSpool.html', { animation: 'slide' })

}
else {
alertTitle = "Failed";
}

ons.notification.alert({
message: $scope.returnedStatus.Message,
title: alertTitle,
modifier: true
});
});
});//end promise

最佳答案

我不能写评论,所以我会回复。根据我的理解,您的 http post 请求应该运行一次。我没有机会看,但也许在

$scope.getActiveSpools().then(function (promise)

由于 $digest,调用运行了两次。可以从https://docs.angularjs.org/api/ng/type/查看$rootScope.Scope#$digest

这可能会引导您找到正确的答案。很抱歉没有完全回答您的问题。

关于javascript - Angular HttpPost 在 REST 中执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39347170/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com