Angular资源获取请求已被取消

时间:2016-09-15 09:37:22

标签: javascript angularjs

我有一个小型angulaerjs应用程序,它在其中一个控制器中使用angularjs资源。以下是资源使用的代码

  $scope.getFilteredTasks = function (filter) {

        var resource = $resource('{0}/api/orderTasks/filterTasks'.format($scope.baseUrl), { status: '@status', type: '@type', createdDate: '@createdDate', agentType: '@agentType', page: '@page', pageSize: '@pageSize' }, {
            'response': { method: 'GET', isArray: false }
        });

        $('#loading').show();
        resource.response({
            status: filter.status,
            type: filter.type,
            createdDate: filter.createdDate,
            agentType: filter.agentType,
            page: $scope.currentPage,
            pageSize: $scope.pageSize
        },
            function (result) {
                $scope.resultTasks = result.Items;
                if ($scope.totalItems != result.TotalCount)
                    $scope.totalItems = result.TotalCount;
                $('#loading').hide();
            },
            function (result) {
                $('#loading').hide();
                alert('Error in request!')
            });
    };

当页面首次加载时,一切都很好,我得到了我需要的所有数据。但是当我发出第二个请求时(例如,按下调用 getFilteredTask(过滤器)功能的页面上的按钮)。我有一个result.status = -1。根据Fiddler和Chrome网络选项卡中的开发工具请求状态为200但已被取消。我还检查了后端并发现没有问题,请求被处理完毕,服务器返回了我需要的所有数据,但我在客户端获得了请求。

更新

就像这个问题只出现在Chrome中一样。例如,在IE 11中,一切正常

1 个答案:

答案 0 :(得分:0)

问题可能是您从链接发出ajax请求,而不是阻止链接被跟踪。因此,如果您在onclick属性中执行此操作,请务必return false;