If you don't ever need to do more than one ajax request of this type at the same time:
var isSpecificRequestOk = true; // variable declaration has to be outside function. Scope needs to be global, not limited to inside your function.
function doSpecificRequest() {
if (isSpecificRequestOk) {
isSpecificRequestOk = false; // Don't do any other request of this type
startAjaxRequest();
}
}
function requestSpecificResultHandler() {
if (requestCompleted && everythingWentOk) {
// ... do more stuff
isSpecificRequestOk = true; // Once again accept requests of this type to be sent.
}
}
Other than this solution, it's hard to give feedback due to lack of knowledge about how you do things. It could be that your server side code is not able to deal with multiple concurrent requests, or that your javascript handling of multiple calls is screwed up.
If you have defined an object to deal with ajax requests and instantiate a new object for each call, then there is no risk of a request overwriting data belonging to other requests, at least not until they start dealing with the server's response. If the result is eventually dumped in a div with someDiv.innerHTML = data, then the latest completed response will obviously overwrite previous ones.
This code should be able to handle multiple concurrent requests, IF the server side code is able to.
function doRequest() {
// New object. No matter how many times you call this function, each ajax request will not overwrite data from other requests.
var ajax = new Ajax();
ajax.remotePoint += "somefile.php";
// resultHandler is called only when the request has been completed and if everything is ok
ajax.resultHandler = function(data) {
// do stuff with the result
// Assuming the argument data is an ordinary string, this will just append it to the document body. Each request should end up creating output here, as long as the request is completed.
var d = document;
d.childNodes[1].appendChild(d.createTextNode(data));
}
ajax.startRequest();
}