I'm not sure where I should handle the response of my ajax request.
There are 2 flavours.
- handle via success/error callback from $http.
- handle via then() method from promise result.
Both responds as expected. But, I suppose that there is a 'catch' where to use each one. Google didn't show me the way. And angular.js source code is kinda... cryptic for me.
Notice: My example (1) always responds first and then (2) responds next. I think is just because localhost latency is nearly null and they both are async method.
$http({
method: 'POST',
url: 'ping.php',
headers: {'content-type' : 'application/json'}
}).
success(function(data, status, headers, config) {
console.log("Flavour one success");
}).
error(function(data, status, headers, config) {
console.log("Flavour one error");
}).then(function() {
console.log("Flavour two success"); },
function() { console.log("Flavour two error");
});