Hello All,
I’m trying to run few requests in parallel – to save time.
Apparently even though I use async requests, and even though looks like it’s indeed async (later lines of code are being executed BEFORE results are returned) – it doesn’t really run in parallel.
When I look at the webserver’s log, I see that only AFTER I get response for the first request, the next request is sent.
Am I doing something wrong? or is it a known limitation?
Here’s my code:
[code=html]
<script type=”text/javascript”>
var str = new String();
function ajax(url){
if (window.XMLHttpRequest){
var obj = new XMLHttpRequest();
}else{
var obj = new ActiveXObject(“MSXML2.XMLHTTP.3.0”);
}
obj.open(“GET”, url, true);
obj.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”);
obj.onreadystatechange = function(){
if (obj.readyState == 4 && obj.status == 200) {
if (obj.responseText){
alert(obj.responseText);
}
}
}
obj.send(null);
}
ajax(“/ajax_in.php”);
ajax(“/ajax_in.php”);
ajax(“/ajax_in.php”);
ajax(“/ajax_in.php”);
</script>
ajax_in.php:
[code=php]
<?
sleep(rand(1,10)); // Random sleep
print date(“H:i:s”); // Print current time; if ajax was parallel I’d get it unsorted.
?>
Thanks in advance!
– Oren