I am executing simultaneous ajax request on a button click.
I have a table with a list of alarms and each row has it's own button that once clicked tries to clear the alarm in the db and then I remove it from the table.
I can click on these buttons one after another and trigger an ajax request.
Problem:
lets say I click on a button and for some reason this is taking time and the user manages to click on yet another button to start a new ajax.
I want to execute a script block in my ajax succes method ONLY if all the ajax requests in the current scope are finished.
code:
$(".signAlarm")
.on("click",
function () {
var _this = $(this).parents(".alarmRow");
var alarm = {
Id: $(_this).data("id")
}
$.automation.worker.postJson("/Alarm/SigAlarm",
JSON.stringify({ alarm }),
function (data) {
if (!$.automation.worker.ajaxActive()) {
// execute this if all the sign alarm attempts are finished
}
$(_this).remove();
});
});
ajaxActive function:
ajaxActive: function() {
if ($.active) return true;
return false;
}
when searching for an answer I found jquery.active which I use in the attempt above but when I check the jquery.active in my success method it is "1" and not 0 even though only one button click has been made.
I also checked this post which got me thinking of jquery.active above but alos $.ajaxStart and $.ajaxStopp.
The problem with $.ajaxStart and $.ajaxStopp and far as I understand is that they are global and I want specific code to execute when these alarms are signed and don't wish for this to happen on every page when an ajax is made.
How do I manage this?