I have this general method to use AJAX calls in a app:
function doAjaxCommand(url, type, async, params, successCallback, failCallback) {
$.ajax({
url: url,
type: type,
async: async,
dataType: "json",
data: JSON.stringify(params)
contentType: "application/json; charset=utf-8",
success: function(result) {
if (result.Success) {
successCallback(result);
} else {
if (failCallback !== undefined) {
failCallback(result);
}
return false;
}
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
console.log(xhr);
console.log(status);
}
});
}
I heard that using promises I can take a better use from async operations. However, I have no clue how to use promises. I've never used it, and I don't get the whole idea in some links I read about. Can you guys please give me a light about it? Even how to start thinking?
Any help would be apreciated, thank you!