onreadystatechange太慢了

时间:2013-05-29 20:10:30

标签: javascript ajax

有谁知道我做错了什么或为什么AJAX回调太慢了?这是代码:

function new_xmlhttp() {

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

    return xmlhttp;
}

function ajax_get(data, args) {

    xmlhttp = new_xmlhttp();

    xmlhttp.open("GET", "functions.php?" + data, true);

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            // OK.
            alert(args);
        }
    }

    xmlhttp.send(null);
}

有时加载需要2-3秒(数据最长10个字节。)

在Linux下测试Firefox和Chrome。

0 个答案:

没有答案