• Advertisement
Sign in to follow this  

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

This topic is 2865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.checked )
    {
      $.post( 'delete_message.php', { message: ID_Array } );
    }
  }
  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
Advertisement
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
You'll also be happy to know that jquery 1.4+ has support for sending back arrays.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement