这是我的HTTP GET请求AngularJs HTTP GET响应
$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”和这个回应的“地位”?
可以显示'backend'代码?它取决于你从后端发送'status'和'response'的内容。 –
1)使用'params'配置,而不是连接查询参数。 2)你的后端应该返回一个实际的HTTP错误响应状态码,用于不成功的请求。 3)使用'==='或'=='进行比较,而不是'=';这是用于作业 – Phil
4)你想要的数据实际上是在'response.data.success','response.data.data','response.data.error_code'等等 – Phil