What is the difference between the "success" and "then"?
then()
takes a single argument: the http response object. success()
takes 4 arguments: the data of the response, the status of the response, the headers of the response, and the http config object. success()
is thus easier to use when all you care about is the data returned. As said by New Dev, the returned value is different: then()
returns a new promise for whatever is returned from its callback and allows you to return a new value and thus build a promise chain, whereas success()
returns the original promise.
A promise means something that would be executed in the future
No, not really. A promise is the result of something you execute now, but for which the result is not immediately available. Since JavaScript is single-threaded, you can't just block and wait for the result, because that would completely freeze the application. So you just register a callback function that will be called, asynchronously, when the result is available. For example:
$http.get('/some/url')
immediately sends an HTTP request. But to get the result, we need to wait for the bytes to travel to the server, for the server to handle the request and send back a response, and for the response to travel to the browser. This could take several seconds. So what $http.get() returns immediately is a promise: i.e. an object which represents a future result (or, once the result has been received, a result that was once future).