9
I have a web application that performs several calls ajax. My college professor challenged me to create a generic message and combine the whole error treatment into a single function. Someone could help me ?
function getShoes() {
$.get( "/Shoes/List", function( data ) {
shoes = data;
}).fail(function() {
toastr.error('Erro ao buscar sapatos')
});
}
function getCoats() {
$.get( "/Coats/List", function( data ) {
coats = data;
}).fail(function() {
toastr.error('Erro ao buscar casacos')
});
}
Basically, the task is to eliminate redundancies. Where there is repetition of codes, you must automate, leaving in a more generic way a single function that performs such processes since the parameters and the return are the same.
– Daniel Omine