【发布时间】:2017-04-18 05:35:18
【问题描述】:
这是我的 HTTP 获取请求
$http({
method: 'GET',
url: baseURL + '/couponManager/createCoupon?token=' + token + query1 + query2 + query3 + query4 + query5,
}).then(function successCallback(response) {
if (response.status = 200)
{
$scope.showSuccessAlert = true;
$scope.successTextAlert = "Coupon successfully created!";
}
else if (response.status = 304)
{
$scope.errorAlert = true;
$scope.errorTextAlert = "Something Went Wrong, Please try again!";
}
}, function errorCallback(response) {
$scope.errorAlert = true;
$scope.errorTextAlert = "Can't reach server, please try later!";
});
这是我得到的回应
{"success":"no","data":{},"error_code":"DW3","error_description":"Server Error"}
但我收到的状态仍然是 200,如何从这个响应中检索“error_description”和“status”?
【问题讨论】:
-
你能显示
backend代码吗?这取决于您从后端发回status和response的内容。 -
1) 使用
params配置而不是连接查询参数。 2) 您的后端应该为不成功的请求返回一个实际的 HTTP 错误响应状态代码。 3) 与===或==进行比较,而不是=;那是为了分配 -
4) 你要的数据其实在
response.data.success、response.data.data、response.data.error_code等中 -
你能做到
console.log(response)并展示它的样子吗? -
@Phil 非常感谢!我需要检查 response.data.success。这就是我所缺少的
标签: angularjs error-handling get