Sign in to follow this  
SteveDeFacto

[web] $.post does not work in a loop?

Recommended Posts

SteveDeFacto    109
I have to execute a php script on my server to tag a message as deleted but when I do more then one or two at a time it skips them. Here is an example:
function Delete(chk)
{
  for (i = 0; i < chk.length; i++)
  {
    if( chk[i].checked )
    {
      $.post( 'delete_message.php', { message: ID_Array[i] } );
    }
  }
  window.location.reload()
}

Is there anyway to make the server process every request without skipping any?

Share this post


Link to post
Share on other sites
Sneftel    1788
You'll need to do only one post() function in the loop, passing a callback function which then does the next post() and passes a callback, etc.

What would be much cleaner and faster and easier, though, would just be to have delete_message.php support deleting multiple IDs at a go.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this