I have a AJAX jQuery chat application, it works by asking for new messages, at the start it just asks for 20 most recent messages, then it gets the count of the latest message, so when it asks again, it knows what the last message ID was, and the server returns message since then.
The issue is on slower connections, it takes longer then the rate it requests, resulting in getting more then one of the same message because there are more then one request running with the same old message ID.
How would I make sure it only is running one request at a time?