Where you're checking the request status you're creating a new request each time. You need to store the XHR object from the request and use that (untested):
var xhr = $.post("/myhandler.php", params);
while (xhr.status != 200);
Alternatively you could use a globally accessibly variable which states whether there is a pending request or not. When a request is sent, set it true, when the response is received set it false. HTH --rob On 6/11/07, Phil Glatz <[EMAIL PROTECTED]> wrote:
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?
-- Rob Desbois Eml: [EMAIL PROTECTED] Tel: 01452 760631 Mob: 07946 705987 "There's a whale there's a whale there's a whale fish" he cried, and the whale was in full view. ...Then ooh welcome. Ahhh. Ooh mug welcome.