2016-09-15 35 views
0

我有一個小的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(filter)函數)。我有一個result.status = -1。根據開發工具請求中的Fiddler和Chrome Network標籤,狀態爲200,但被取消。我也檢查了後端,發現沒有問題,請求被處理成功,服務器返回了我需要的所有數據,但我在客戶端獲得了可請求的請求。

UPDATE

它loooks這樣的問題只出現在Chrome。例如,在IE 11中,一切正常

回答

0

問題可能是您從鏈接發出ajax請求,而不是阻止鏈接被跟蹤。因此,如果您在onclick屬性中執行此操作,請確保return false;