function requestAjax(url, metodo, data, successCallback) {
$.ajax({
url: url,
type: metodo,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
statusCode: {
200: () => {
successCallback();
}
}
});
}
function adicionarNovaCategoria() {
if ($("#nova-categoria-input").val() !== '') {
var categoria = {
nomeCategoria: $("#nova-categoria-input").val()
};
requestAjax("/api/categorias-componente", "POST", categoria, function () {
showAlertaVerde("Item adicionado!");
getTodasCategorias();
$("#nova-categoria-input").val('');
});
} else {
showNomeInvalido();
}
}
The function that I pass as callback on the second addNewCategory function is performed before entering the requestAjax function.