连续发送的JavaScript请求(不当行为)

时间:2017-10-19 07:26:11

标签: javascript promise

我们的javascript应用程序遇到问题。我们在Angular 1.5应用程序中有以下方法。这种方法有时在被调用时会继续无限期地运行。我们遇到过这样的情况,即该功能继续运行并向服务器发送请求数小时,并发现请求最多为4000个。

如何确保请求只发送一次?

var normalVisitAuthorization = function(cardNo) {
  $scope.authorizePromise =
    $q.all([VerificationService.authorizeCardWithVisit(cardNo, $scope.logininfo.FacilityCode, $scope.logininfo.UserName, $scope.visitType.selected.TypeID, 1), VerificationService.getLastVisits(cardNo)])
    .then(function(results) {
      console.log(results[0]);
      if (results[0].CardExistence.indexOf('MISSING') != -1) {
        $scope.memberDetails = undefined;
        DevExpress.ui.notify({
          message: 'The card was not found in NHIF Database. The 
          beneficiary should submit the card to the nearby NHIF office
          for
          verification ', 
          position: {
            my: "center center",
            at: "center center"
          }
        }, "warning", 7500);
      } else {
        $scope.memberDetails = results[0];
        $rootScope.memberDetails = results[0];
        $scope.lastVisits = results[1];
      }


      $scope.imageSrc = ngAuthSettings.verificationUrl + "GetImage?CardNo=" + cardNo;
      console.log($scope.imageSrc);

    }, function(error) {
      console.log(error);
      DevExpress.ui.notify({
        message: error.data.ExceptionMessage,
        position: {
          my: "center center",
          at: "center center"
        }
      }, "warning", 4500);

    });

}

0 个答案:

没有答案