Two AJAX asynchronus GET call: Only one get the xml file

Posted by Woho87 on Stack Overflow See other posts from Stack Overflow or by Woho87
Published on 2011-02-10T23:22:29Z Indexed on 2011/02/10 23:25 UTC
Read the original article Hit count: 189

Filed under:
|
|

Hi!

I have two AJAX GET calls that are set to asynchcronus = true;

I want to obtain two XML files on my server. The two AJAX calls and rendering are defined in function foo & koo. And are called simultaneously.

function foo(){
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
             var xmlDoc = xmlhttp.responseXML;
             //Do something
        }
    }
    xmlhttp.open('get', 'url', true);
    xmlhttp.send();
}
function koo(){
    //Almost the same as function foo
}
foo();
koo();

I've noticed that inside the if statement in the first function call(foo), the code their will never compile. While in the second function call(koo). The code inside the if statement can be compiled. If I set both asynchronus to false, then there is no problem at all. If I remove the second function call(koo) from the code, than the code inside the if statement can be compiled.

What can I do to have both asynchronus AJAX calls?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about Xml