Angularjs - $http success vs then

佐手、 提交于 2019-12-08 02:34:14

问题


I want to ask about the difference about this method My concern is difference between .then and .success, function and also .error thanks.

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

and

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

回答1:


Both .then() and .sucess() are refer to promise it run asynchronously and wait for the response if it fullfied your request then resolve it otherwise reject it.

.success and .error are deprecated you can find more details on documentation



来源:https://stackoverflow.com/questions/38627623/angularjs-http-success-vs-then

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!