Hello, I have two AJAX requests which are depended on each other. One is for retrieving chat messages, and another - for sending. Here's the code. First - message "getter".
function getData() { setTimeout("getData()", reloadTimeout); $.ajax({ type: "GET", url: "chat.php", success: function(xhr) { getDataXHR = xhr; getDataEvent(); }, error: function() { getData(); } }); } Second one, now - message sender. function send (msg, to) { $.get("send.php", { msg: msg, userId: userId, to: to } ); } The issue: Messages get "swallowed" sometimes, probably because of getData() function requesting chat.php and the message is sent the same time as the getData() request. What i need to is; wait until getData() is done (or isn't even initiated) and THEN send the message. YES, i have Googled, tried different options, but i can't find the right solution.