【发布时间】:2018-02-05 07:22:33
【问题描述】:
如果我有一个 API 服务器,那么 API 会发送 JSON 格式的 ajax 数据:
{"status":304,"message":"Cannot delete data where PK is empty or > 1"}
如何在 AngularJS $http post 调用状态和消息来提醒 bootbox? 这是我的 AngularJS $http 帖子
$http({
method: "POST",
url: apiUrl('disable_assethw'),
data: {
id: id
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function successCallback(response) {
if(response.status == 304) {
bootbox.alert("Something went error.." + response.data.message);
} else {
$scope.getAssetHW();
}
}, function errorCallback(response) {
bootbox.alert("Something went error.." + response.status);
});
感谢您的建议。
【问题讨论】:
-
你说它的 json 在这里你提到
{'Content-Type': 'application/x-www-form-urlencoded'} -
除非你改变了默认的
requestTransformer,否则{id: id}肯定不是application/x-www-form-urlencoded请求的有效载荷 -
等等,您问题顶部的 JSON 是来自服务器的响应负载吗?如果是这样,你想要
if (response.data.status == 304) -
抱歉内容类型,我的意思是。如何在 jquery 上调用
{"status":304,"message":"Cannot delete data where PK is empty or > 1"}like success 属性。对不起我的英语不好 -
感谢您的帮助,我找到了我的解决方案,就像你说的那样打电话@phil response.data.status / message。然后我清除缓存我的浏览器和陷阱,警报显示。谢谢大家。
标签: javascript angularjs angularjs-http