2014-01-09 2 views
5

나는 며칠 동안 이것을 뒤집어 썼고, 내가 뭘 잘못하고 있는지 파악할 수 없기 때문에 어떤 생각이나 어둠 속에서도 촬영할 수 있습니다. AngularJS $ http get 메서드를 사용하여 사용자에게 나머지 서비스의 응답을 표시하려고하는데, 데이터 객체를 콘솔에 인쇄하면 숫자 200이 일관되게 나타납니다 (나는 꽤 확신하고 있습니다). 내 상태 코드). 매번 성공을 거두고 요청을 보내면 Chrome 디버그 도구가 내게 올바른 모든 데이터가 포함 된 응답을 표시합니다. 변수를 표시 할 수없는 것 같습니다. 네가 무엇이든 생각하면 나 한테 알려줘! 감사!

내 자바 스크립트 :

$scope.resendDestinations = []; 
$scope.resendDestGet = function() { 
    var omtTypeCodeString = ''; 

    for(var i = 0; i < $scope.mySelections.length; i++){ 
     if(omtTypeCodeString == ''){ 
      omtTypeCodeString = $scope.mySelections[i].orderHeader.omtOrderTypeCode; 
     } 
     else{ 
      omtTypeCodeString = omtTypeCodeString + ',' + $scope.mySelections[i].orderHeader.omtOrderTypeCode; 
     } 
    } 

    $http({ 
     method: 'GET', 
     url: restService.pom + //service url, 
     respondType: 'json', 
     headers: { 
      'Accept': 'application/json', 
      'Content-Type': 'application/json', 
      'Access-Control-Allow-Credentials': true 
     }, 
     params: { 
      orderTypeCode: omtTypeCodeString, 
      transactionCode: 3 
      } 
     }).success(function (status, data, response, header) { 
      console.log("Success!"); 
      //TODO see if this is being used... has to be 
      status = parseInt(status); 
      $scope.resendDestinations = data.multipleOrders; 
      if (status == 200 && $scope.resendDestinations.length == 0) { 
       $scope.bigAlert.title = 'Error', 
       $scope.bigAlert.header = 'Search Error'; 
       $scope.bigAlert.content = 'Current search parameters do not match any results.'; 
       $scope.showBigAlert(); 
      } 
      else{ 
       $scope.resendDestinations = data; 
       console.log("Data DestinationList here: "); 
       console.log($scope.resendDestinations); 
       console.log(data.multipleOrders); 
       console.log(data); 
      } 
      $scope.isSearching = false; 
     }).error(function (response, data, status, header) { 
      //Do error things 
     }); 
    return $scope.resendDestinations; 
}; 

그리고 서비스 응답 :

[{"destCode":3,"destDescr":"Repository","attributes":null},{"destCode":4,"destDescr":"Pipeline","attributes":null},{"destCode":1,"destDescr":"Processor","attributes":null},{"destCode":2,"destDescr":"DEW","attributes":null}, {"destCode":7,"destDescr":"Management System","attributes":null}, {"destCode":8,"destDescr":"Source","attributes":null}]

+0

기능 헤더의 상태 및 데이터 순서를 변경하십시오. – Beterraba

답변

14

당신은 잘못된 순서로 인수를 가지고있다. 그것은해야한다 :

success(function(data, status, headers, config).then() 방법은 일반적으로 바람직하고, 또한 docs here (click).

참조하십시오. 이 코드로 전환하면 다음과 같은 데이터에 액세스하게됩니다.

.then(function(response) { 
    var data = response.data; 
    var status = response.status; 
    //etc 
}); 
+0

와우 ... 내가 바보라고 믿을 수 없어. 나는 사소한 것이 빠져 있다는 의심의 여지가 있었다. 답변 감사합니다! 나는이 모든 것을 처음 접했고 큰 도움이되었습니다. – AndyVan

+1

@AndyVan 문제 없습니다! 때로는 잠시 쉬고 나서 다시 문서를 살펴 보는 것이 가장 좋습니다 : – m59

+1

'.then()'과'.success()'및'.error()'를 사용하는 것에 대한 커다란 조언. –

관련 문제