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!
我已经仔细研究了这几天,仍然无法弄清楚我做错了什么,所以任何想法甚至黑暗中的镜头都会受到赞赏。我试图使用AngularJS $ http get方法向用户显示来自休息服务的响应,但是当我将数据对象打印到控制台时,我始终收到数字200(我相当肯定它给出了我的状态代码)。我每次都取得成功,在发送请求后,Chrome调试工具会向我显示包含所有正确数据的响应。我似乎无法让它出现在变量中以供显示。如果你想到什么,请告诉我!谢谢!
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}]
[{ “destCode”:3 “destDescr”: “库”, “属性” 日期null},{ “destCode”:4 “destDescr”: “管道”, “属性” 日期null},{ “destCode”: 1,“destDescr”:“Processor”,“attributes”:null},{“destCode”:2,“destDescr”:“DEW”,“attributes”:null},{“destCode”:7,“destDescr”: “管理系统”,“属性”:null},{“destCode”:8,“destDescr”:“源”,“属性”:null}]
1 个解决方案
#1
14
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()方法。如果切换到那个,您将访问如下数据:
.then(function(response) {
var data = response.data;
var status = response.status;
//etc
});
#1
14
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()方法。如果切换到那个,您将访问如下数据:
.then(function(response) {
var data = response.data;
var status = response.status;
//etc
});