I am still new to Javascript. I am developing a simple page where I click a button fetching a value on a servlet and displays it. It works well, unless I click like crazy on the button. Sometimes, the displayed result is null.
I am wondering whether this is caused by simultaneous calls to the same following function:
function loadXMLDoc2(retr) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            $("#" + retr).button('option', 'label', xmlhttp.responseText);
            // document.getElementById(retr).innerHTML=xmlhttp.responseText;
        }
    }
    var param = "cmd=" + encodeURIComponent(retr);
    document.getElementById("TOP_LEFT").innerHTML = param;
    xmlhttp.open("GET","/WebFront/Asynclet?" + param,true);
    xmlhttp.send(null);
}
Is Javascript thread-safe? And if not, how can I synchronize or isolate calls to this method?
 
     
    