Ajax中的setTimeout

时间:2012-02-05 06:26:07

标签: ajax settimeout

我试图在2秒后加载这个ajax代码但是它一直在重装,我尝试了setTimeout但是还没有成功,可以告诉我我做错了什么

    <!--
    function Ajax_Filter(url, containerid) {

    var bustcachevar = 1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
    var rootdomain = "http://" + window.location.hostname
    var bustcacheparameter = ""

    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject) { // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        }
        catch (e) {
            try {
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
            catch (e) { }
        }
    }
    else
        return false
    page_request.onreadystatechange = function () {
        loadpage(page_request, containerid)
    }
    if (bustcachevar) //if bust caching of external page
        bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()
    page_request.open('GET', url + bustcacheparameter, true)
    page_request.send(null)
    }

    function loadpage(page_request, containerid) {
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
        document.getElementById(containerid).innerHTML = page_request.responseText;
        //var start_delay = Ajax_Filter('pagetoload.asp', 'div_id');
        //clearTimeout(start_delay);
        //setTimeout("Ajax_Filter('pagetoload.asp, 'div_id')", 1000); //does nothing
        setTimeout(Ajax_Filter('pagetoload.asp', 'div_id'), 1000);//keeps reloading
        //setTimeout((start_delay), 1000);
    } 
    else {
    document.getElementById(containerid).innerHTML = "<div>loading etc<br>" + page_request.statusText + "</div>";
    }
}
    // onclick"Ajax_Filter('pagetoload.asp','div_id');top.frames.MainFrame.location.href='main.asp';" //my link I am using
    //-->

任何人都可以向我展示这个的工作版本

0 个答案:

没有答案