Gledders;1156285 wrote:
This was my understanding (possibly flawed,) that if for example, request a) is made slightly before request b), but request b) takes less processing time at the server, the function can not distinguish for which request it is receiving the response unless the request is manually identified. Otherwise the function simply processes responses in the sequence it receives them? It simply detects a ready-state change and processes the response.
yes and no. while there isn't a uri on responseText, i belive xml docs have a uri property of some sort that identifies the source.
regardless, async ajax takes a function and functions can store values via closure, so it all depends on how you use your callback.
here is a simple ajax function that passes three args to the callback, in order of most-to-least used: responseText, the whole xmlHttpRequestObject, and the url making the request:
function aGet(turl, callback) {
var XHRt = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
XHRt.onreadystatechange = function () {if (XHRt.readyState == 4 && XHRt.status == 200) {callback(XHRt.responseText, XHRt, turl);}};
XHRt.open("GET", turl, true);
XHRt.setRequestHeader("Content-Type", "text/html");
XHRt.send("");
return XHRt;
}
aGet("/forum/", function(txt, xml, url){
alert( url );
});
aGet("http://webdeveloper.com/forum/newreply.php?do=newreply&p=1156285", function(txt, xml, url){
alert( url );
});
in the above code, sometimes the main page is first, sometimes the thread view page is first, but they always both work and are identifiable.