Hey there, I'm just starting out with javascript and AngularJS. Here's a function I wrote to retrieve JSON data from the server:
function getProducts() {
return $http.get(urlProducts).then(
//Success
function(response) {
products= response.data.result;
return products;
},
//Error
function(response) {
//put best way to return an error
return something;
}
);
}
My main question is: what is the most efficient method for fetching data from a web server? I not only want to confirm if the response was successful but also check if the status code returned was 200.
In case of an error, I'd like to know the best approach to handle it (which involves displaying an image with the text "Not possible connect with the server. Try it again"). However, I am building the app with Ionic (using HTML5, CSS3, and javascript with AngularJS). So, what would be the optimal way to show an error message involving an image while working in Apache Cordova? Thanks!