I have a jquery Ajax function
var arr = {
id: 1,
run: true
}
$.ajax({
url: '@Url.Action("Getdata", "Details")',
data: { Batch: arr},
type: "POST",
success: function (result) {
if (result) {
GenNamespace.Completed(result);
}
},
error: function (result) { alert("Problem Occured"); },
});
which calls c# async function, and on successful completion of the task i am executing some function in jquery ajax success
public async Task<JsonResult> GetData(Batch arr)
{
try
{
var success = false;
var t = await Task.Run(() =>
{
//i am Performing long running task here
return Json(success, JsonRequestBehavior.AllowGet);
}
});
return t;
}
catch (Exception ex)
{
throw ex;
}
return null;
}
however this is a async function, so the value(success = false) gets returned to the jquery success even though the function is not completely executed, so how do i call the javascript function only upon completion of this task, is there a task completed notification or something which i could use here in this scenario?