Following the code below, is there a better way to call the sendEmail () method after receiving "success" in ajax called by the gravaVisita () method? Notice that I used callback as a solution to this problem.
There are 2 "js" files:
The first file has the gravaVisita () method that is called by the view:
this.gravaVisita = function (visitado, visitante) {
if (visitado == visitante)
return;
dataBD.gravaVisita(visitado, visitante,
function (data) {
if (data.statusRetorno == 200)
dataBD.enviaEmail();
}
);
}
The second is responsible for making an ajax call to the "GravaVisita" action of the "AccountMVVM" controller
function DataBD() {
this.gravaVisita = function (visitado, visitante, callback) {
var dataJson = {
LoginFoiVisitado: visitado,
LoginVisitou: visitante
};
$.ajax({
type: "POST",
dataType: "json",
url: "/site/apiPostForm/AccountMVVM/GravaVisita",
data: dataJson,
success: function (data) {
if (callback) callback(data);
},
error: function (error) { }
});
}
}
var dataBD = new DataBD();