Progress Bar for execution in javascript

I need to show a progress bar using javascript if some execution is happening.
I saw example in student attendance tool, the code is:
frappe.confirm(__(“Do you want to update attendance?
Present: {0}

Absent: {1}”, [students_present.length, students_absent.length]),
function() { //ifyes
if(!frappe.request.ajax_count) {{
method: “”,
freeze: true,
freeze_message: “Marking attendance”,
args: {
“students_present”: students_present,
“students_absent”: students_absent,
“student_group”: frm.doc.student_group,
“course_schedule”: frm.doc.course_schedule,
callback: function(r) {
$(me.wrapper.find(“.btn-mark-att”)).attr(“disabled”, false);
function() { //ifno
$(me.wrapper.find(“.btn-mark-att”)).attr(“disabled”, false);

And it works but when I used this same code it generates multiple confirmation windows instead of loader.
Can someone explain the logic of this code?