I'm calling $.post to send some text back to a web server, where it
gets logged. The function is something like this:

function send_message(msg) {
  var params = {};
  params['my_message'] = msg;
  $.post("/myhandler.php", params);
}

It calls a php page that appends it to a log. If I view the log in
real time with tail -f log.txt, I can see the messages.

The problem is that if I set up a page to send 5 messages, they aren't
being displayed sequentially; I might see them in the order 2,1,4,3,5
-- and the order is random each time I call the page. What I would
like to do is wait until the post function completes before continuing
with the next message.

Since the post returns an XMLHttpRequest object, I thought I could try
some thing like:

  while ($.post("/myhandler.php", params).status != 200)

But I think that simply keeps calling the function, making things
worse.

How can I query the post request for success, and not exit my function
until it is done?

Reply via email to