i have i javascript function does not wait ajax execution quit immediately with no wating execution what is the problem seriously my code below:
i made an alert at the end: precisely to stop it. when the alert show i wait a little bit the result from the server and the return is result not null from the server. when i disable the alert the result is undefined.
function getAllBathyms() {
var idbar = $("#list_barrages").val();
var idorg = $("#list_organisations").val();
if (idbar == "" || idbar == "--" || idbar == "NaN") {
alert("veuillez séléctionner un barrage SVP:");
}
if (idorg == "" || idorg == "--" || idorg == "NaN") {
alert("veuillez séléctionner un barrage une agence SVP:");
}
$.ajax({
type: 'POST',
url: '@Url.Content("~/CourbesNiveaux/getAllBathyms")',
data: { 'idbar': idbar, 'idorg': idorg },
success: function (data) {
alert('ok ajax');
console.log('ok ajax');
bathyms = data;
},
error: function () {
alert('server problems');
}
});
return bathyms;
}