Angularjs - $http 成功对比当时

Angularjs - $http success vs then

我想问一下这个方法的区别 我关心的是 .then 和 .success、function 以及 .error 之间的区别 谢谢。

// 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.
});

// Simple GET request example:
$http({
   method: 'GET',
   url: '/someUrl'
}).success(function successCallback(response) {
   // this callback will be called asynchronously
   // when the response is available
}).error( function(data) {
   // called asynchronously if an error occurs
   // or server returns response with an error status.
});

.then().sucess() 都是指异步承诺 运行 并等待响应,如果它满足您的请求然后 resolve 否则 reject它。

.success.error 已弃用您可以在文档

中找到更多详细信息