错误:angular.js编辑表单发送两个put请求

时间:2017-03-22 16:50:26

标签: javascript angularjs

我无法重现此错误或找出原因:用户编辑表单并提交,更改通过PUT请求保存,有数据重新加载的GET请求,但有时会有第二个PUT请求将更改还原为原始值。 我检查了日志,第二个PUT请求发生在第一个PUT请求的几秒钟内。我还没有复制这个,用户说他们没有第二次编辑。

在编辑控制器中:

  $scope.save = function() {
    $scope.requestPending = true;
    APIResources.userResource($route.current.userType,$route.current.params.id).update(makeUpdateObject()).$promise.then(function(data) {
        $scope.userRefresh();
        $scope.requestPending = false;
        $rootScope.$broadcast('app.event.user.updated');
    },
    function(error){
      console.log('Error saving', error);
    });
    $scope.$dismiss();
  };

在用户控制器中:

  $scope.userRefresh = function() {
    APIResources.userResource($route.current.userType,$route.current.params.id).get().$promise.then(function(data) {
      $scope.user = data;
      // Time to reload the data is 2000ms to support 2G (450kbs) or higher 
      window.setTimeout(function() {
        $rootScope.$broadcast('app.user.loaded', data, userType);
      }, 2000);
    }, function(err) {
      console.log('Data failed to load.');
    });
  };

0 个答案:

没有答案
相关问题