问题
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