Order of operations

Order of operations

Hello:

I'm having a problem with order of operations, and hoping someone here can help. The routine in question, deletes members from a group, and then displays the new group membership without deleted members. The routine uses two different files, because the select query used for displaying group members is called in other routines within the application. It only makes sense to use the same SELECT statement in the same file (easier maintenance). Following is the snippet of code in question:

  1. //======================== Delete selected individuals from Group =======================
  2. $('#removeMember').click(function() {
  3.     var removeAnswer = confirm("Do you really want to remove the selected user(s)?");
  4.     if (removeAnswer){
  5.         $.post("org_users_data6.php",{bind_MemberArray:MemberArray},function(data){
  6.         console.log("1st Post Return: " + MemberArray);
  7.         });
  8.         $.post("org_users_data5.php",{bind_GrpArray:grpID_Array},function(data){
  9.             console.log("2nd Post Return: " + data);
  10.         $('#MemberBody').html(data);
  11.         });
  12.         // Reset select options to reflect deleted group
  13.         $('#AddMemberOpt').html('Add Individuals to <b><u>ONE</u></b> Selected Group');
  14.        
  15.         // Reset applicable Arrays - so that deleted members don't remain in play for other procedures.
  16.             MemberArray = new Array();
  17.             tableRow = '';
  18.     }
  19.     // ### ADDED: 01-27-13 to reset and clean after action
  20.     $('#new_OrgGrp').val('');
  21.     $('#GroupSelect').val(0);
  22. });
The problem is that sometimes the above routine executes in order (with the first $.post executing BEFORE the second $.post) and all is well.

But, if I run the routine repeatedly (by deleting members multiple times - one right after the next) then the routine runs out of order. My console log shows console.log("2nd Post Return: " + data); BEFORE console.log("1st Post Return: " + MemberArray);. The end result is that the member is deleted, but the returned recordset does NOT reflect the deletion.

It is entirely probable that users would delete contacts from the group, and then realize they forgot to delete a contact, and run a second delete.

Does anyone have any idea why the above $.posts do not execute in order on multiple delete actions? And how do I solve the problem?

Thanks Much:

Pavilion