Angularjs - $ http成功与当时

san*_*tro 2 javascript api angularjs angular-http angular-promise

我想问一下这个方法的不同之处我的关注点是.then和.success,函数以及.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.
});
Run Code Online (Sandbox Code Playgroud)

// 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.
});
Run Code Online (Sandbox Code Playgroud)

Was*_*mad 6

这两个.then().sucess()是指保证它异步运行,并等待回应,如果它fullfied您的请求,那么resolve它,否则reject它.

.success并且.error已弃用,您可以在文档中找到更多详细信息