Question about AJAX

Posted by Doug on Stack Overflow See other posts from Stack Overflow or by Doug
Published on 2010-05-17T06:29:42Z Indexed on 2010/05/17 6:30 UTC
Read the original article Hit count: 289

Filed under:
function showHint(str) {

    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("games").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","hw9.database.php?name="+str,true);
    xmlhttp.send();
}

I'm learning AJAX at the moment. The code here basically receives the echo from the PHP and then puts it in element id games. My question is, if I wanted to have AJAX send 3 different http requests to 3 different PHP scripts and if I wanted to retrieve data from each one and then put it in 3 different element id's then would I make 3 copies of this same function? I would imagine that there should be a more efficient way. Thanks!

© Stack Overflow or respective owner

Related posts about AJAX