響應,如果我有一個API服務器,則API與JSON格式發送AJAX數據:
{"status":304,"message":"Cannot delete data where PK is empty or > 1"}
如何AngularJS $ HTTP POST調用狀態和消息,以提醒bootbox? 這裏我的AngularJS $ http post
$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'}' – harishr
除非你改變了默認'requestTransformer','{id:id} ''application/x-www-form-urlencoded'請求肯定不是有效負載 – Phil
等待,請問您的問題頂部的JSON是來自服務器的響應負載嗎?如果是這樣,你想'if(response.data.status == 304)' – Phil