Angularjs - $http 成功 vs then [英] Angularjs - $http success vs then

查看:20
本文介绍了Angularjs - $http 成功 vs then的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

// 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() 都是指 promise 异步运行并等待对于响应,如果它满足您的请求,则 resolve 否则 reject 它.

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.error 已弃用,您可以在文档中找到更多详细信息

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

这篇关于Angularjs - $http 成功 vs then的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆