AngularJS $http get data object displays status code instead of response

AndyVan

I have mulled over this for days and can still not figure out what I'm doing incorrectly so any ideas or even shots in the dark are appreciated. I am trying to display the response from a rest service to the user using the using the AngularJS $http get method, but when I print the data object to the console, I consistently receive the number 200 (I'm fairly certain it is giving me the status code). I hit success every time and, upon sending the request, the Chrome debug tool shows me the response with all the correct data. I just can't seem to get it to appear in a variable for display. Let me know if you think of anything! Thanks!

My javascript:

$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;
};

And the service response:

[{"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}]

m59

You have the arguments in the wrong order. It should be: success(function(data, status, headers, config)

See the docs here (click).

Also, the .then() method is generally preferred. If you switch to that, you would access the data like this:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

AngularJs - $http.get request, response with -1 status code

From Dev

$http.get returns Html code in response instead of json object

From Dev

Get $http response error status on AngularJS

From Dev

AngularJS - HTTP GET request with status code 302

From Dev

Get Http Status Code from an ajax response with jquery

From Dev

Http response status code constants

From Dev

How to make $http.get return response instead of promise object?

From Dev

Angular JS using $http() get a response, with status 200, but data is null

From Dev

Is there a way to get HTTP status code name using JS and AngularJS?

From Dev

Is there a way to get HTTP status code name using JS and AngularJS?

From Dev

GET Ajax returns html code in response instead of json object

From Dev

GET Ajax returns html code in response instead of json object

From Dev

AngularJS $http redirect on status code

From Dev

Http Status Code Factory AngularJs

From Dev

Forcing C#'s HTTP Response to Return a Status Code Instead of a Description

From Dev

AngularJs $http timeout response code

From Dev

AngularJS POST Fails: Response for preflight has invalid HTTP status code 404

From Dev

AngularJS $http.head is showing a status code of 0 despite a successful 200 response

From Java

Curl to return http status code along with the response

From Dev

Mule-Setting Status code in HTTP response

From Dev

Get Http Status Code with OkHttp

From Dev

AngularJS With Asp.net Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

From Dev

AngularJS With Asp.net Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

From Dev

How to configure API Response cache with HTTP Response status code?

From Dev

cURL Post request: get response and status code

From Dev

Play framework get Response status code in filter

From Dev

HTTP Status 0 from AngularJS Get for JSON

From Dev

AngularJS - $http get returns error with status 0?

From Dev

AngularJS $http get return null status 0

Related Related

  1. 1

    AngularJs - $http.get request, response with -1 status code

  2. 2

    $http.get returns Html code in response instead of json object

  3. 3

    Get $http response error status on AngularJS

  4. 4

    AngularJS - HTTP GET request with status code 302

  5. 5

    Get Http Status Code from an ajax response with jquery

  6. 6

    Http response status code constants

  7. 7

    How to make $http.get return response instead of promise object?

  8. 8

    Angular JS using $http() get a response, with status 200, but data is null

  9. 9

    Is there a way to get HTTP status code name using JS and AngularJS?

  10. 10

    Is there a way to get HTTP status code name using JS and AngularJS?

  11. 11

    GET Ajax returns html code in response instead of json object

  12. 12

    GET Ajax returns html code in response instead of json object

  13. 13

    AngularJS $http redirect on status code

  14. 14

    Http Status Code Factory AngularJs

  15. 15

    Forcing C#'s HTTP Response to Return a Status Code Instead of a Description

  16. 16

    AngularJs $http timeout response code

  17. 17

    AngularJS POST Fails: Response for preflight has invalid HTTP status code 404

  18. 18

    AngularJS $http.head is showing a status code of 0 despite a successful 200 response

  19. 19

    Curl to return http status code along with the response

  20. 20

    Mule-Setting Status code in HTTP response

  21. 21

    Get Http Status Code with OkHttp

  22. 22

    AngularJS With Asp.net Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

  23. 23

    AngularJS With Asp.net Web API: $http post returning XMLHttpRequest cannot load: Response for preflight has invalid HTTP status code 405

  24. 24

    How to configure API Response cache with HTTP Response status code?

  25. 25

    cURL Post request: get response and status code

  26. 26

    Play framework get Response status code in filter

  27. 27

    HTTP Status 0 from AngularJS Get for JSON

  28. 28

    AngularJS - $http get returns error with status 0?

  29. 29

    AngularJS $http get return null status 0

HotTag

Archive