Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS$timeout在safari中立即执行_Javascript_Angularjs_Http_Safari - Fatal编程技术网

Javascript AngularJS$timeout在safari中立即执行

Javascript AngularJS$timeout在safari中立即执行,javascript,angularjs,http,safari,Javascript,Angularjs,Http,Safari,我对AngularJS中的$timeout有一个奇怪的问题,这个问题只在Safari(iOS和macOS)中出现,而在其他浏览器中没有。Safari不会等待指定的毫秒,而是立即执行该函数。完整的代码可用,但这是代码的相关部分: app.directive('upload', ['$lhttp', '$http', '$interval', '$timeout', '$q', '$location', function ($lhttp, $http, $interval, $timeout, $q

我对AngularJS中的
$timeout
有一个奇怪的问题,这个问题只在Safari(iOS和macOS)中出现,而在其他浏览器中没有。Safari不会等待指定的毫秒,而是立即执行该函数。完整的代码可用,但这是代码的相关部分:

app.directive('upload', ['$lhttp', '$http', '$interval', '$timeout', '$q', '$location', function ($lhttp, $http, $interval, $timeout, $q, $location) {
    return {
      templateUrl: '/.src/views/upload-widget.html',
      controller: function($scope, $element, $attrs) {
      // code ...

      // Define upload function
      vm.uploadFiles = ()=>{
        // code ...

        // Create the payload for the upload request
        let formdata = new FormData();
        formdata.append("salt", salt);
        // code ...

        // Create the upload request
        let request = $http({
          method: 'POST',
          url: "/.src/php/upload.php",
          data: formdata,
          transformRequest: angular.identity,
          uploadEventHandlers: {
            progress: function(e) {
              vm.progress = Math.round((e.loaded/e.total)*100) + "%";
              if (vm.progress === '100%') vm.get_server_progress(salt);
            }
          },
          headers: {'Content-Type': undefined}
        });

        // Create handler functions for success and errors
        request.then(function successCallback (response) {
          vm.server_progress = "100%";
          vm.actually_loading = false;
          $timeout(()=>{ vm.loading = false }, 600);
          if (response.data.error.length) {
            vm.fail = true;
            vm.error_message = response.data.error;
          }
          if (!response.data.log.length) {
            vm.fail = true;
            vm.error_message = $scope.m.text.upload_error;
          }
        }, function errorCallback (response) {
          // code ...
        });
      }

      // code ...

      // Create function for checking status of server side processing of the upload
      vm.get_server_progress = (salt)=>{
        $http.get('/.src/php/status.php?salt='+salt+'&d='+Date.now()).success((data)=>{
          vm.server_progress = data+"%";
          re_get_progress_if(salt);
        }).error(()=>{
          re_get_progress_if(salt);
        });
      }

      function re_get_progress_if (salt) {
        //////////////////////////////////////
        // THIS IS THE PROBLEMATIC $TIMEOUT://
        if (vm.actually_loading) $timeout(vm.get_server_progress, 100, true, salt);
      }
    },
    controllerAs: 'up'
  };
}]);

有人知道这是Safari中的一个bug吗?如果是,我该如何解决问题?

您确定这是立即解决的吗?您是否尝试过更大的延迟值,如5000?另一个超时在Safari中有效?是否尝试增加到更高的值?如果您使用JS的标准
setTimeout
遇到同样的问题,您是否尝试过?