简体   繁体   中英

Why can I not send more than one request?

function stateChanged(idname) { 
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById(idname).value = xmlhttp.responseText;
        }
    }
}
function openSend(php,idname) {
    stateChanged(idname);
    xmlhttp.open("GET",php,true);
    xmlhttp.send(); 
}   
function showHint() {

    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    openSend("time.php", "Time");
    openSend("date1.php", "Date1");
    openSend("date2.php", "Date2");
    return;
}

These two say aborted (in Firebug) and doesn't return a value. Why is that? Is it because I can't send more than 1 request?

    openSend("time.php", "Time");
    openSend("date1.php", "Date1");

If I can't, how could I achieve 3 requests with only one invocation ?

You need to create three XHR (XML HTTP Requests) objects, each should send one request. If you want to stick with one XHR object, you'll have to chain the requests such that after one request is finished (ready state = 4, status = whatever), the next one is fired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM