[英]AngularJS $http get data object displays status code instead of response
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). 我试图使用AngularJS $ http get方法显示从休息服务到用户的响应,但是当我将数据对象打印到控制台时,我始终收到数字200(我相当肯定它是给予我的状态代码)。 I hit success every time and, upon sending the request, the Chrome debug tool shows me the response with all the correct data. 我每次都取得了成功,在发送请求后,Chrome调试工具会向我显示包含所有正确数据的响应。 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: 我的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}]
You have the arguments in the wrong order. 您的参数顺序错误。 It should be: success(function(data, status, headers, config)
应该是: success(function(data, status, headers, config)
See the docs here (click). 请参阅此处的文档(单击)。
Also, the .then()
method is generally preferred. 此外,通常优选.then()
方法。 If you switch to that, you would access the data like this: 如果切换到那个,您将访问如下数据:
.then(function(response) {
var data = response.data;
var status = response.status;
//etc
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.