我将帖子查询发送到服务器(Angular v1.5.5),服务器返回错误500.但是为什么该错误会转到success
回调而不是error
回调函数? Firebug向我显示success
消息,而没有error
消息。
$http.post('someURL', someData)
.success(function (data1) {
console.log('success');
return data1;
})
.error(function (data2) {
console.log('error');
return data2;
});
答案 0 :(得分:1)
这是angular 1.5.5的正确语法:
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
参考:https://code.angularjs.org/1.5.5/docs/api/ng/service/ $ http