开发者

Reload a div by using the same div

i want to wr开发者_Python百科ite a greasemonkey script that reloads every 10 sec. the same div of the same page. But i only know how to load a complete page into a div :( of course my script below does'nt work...

function Ajax(){
var xmlHttp;
    try{    
        xmlHttp=new XMLHttpRequest();
    }catch (e){
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try{
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){
                alert("No AJAX!?");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange=function(){
        document.getElementById('ReloadDIV').innerHTML=xmlHttp.responseText;
        setTimeout('Ajax()',10000);
    }
    xmlHttp.open("GET","#ReloadDIV",true);
    xmlHttp.send(null); 
}
window.onload=function(){
    setTimeout('Ajax()',10000);
}


<div id="ReloadDIV">Text Text</div>


I think one problem is the onreadystatechage which should be:

xmlHttp.onreadystatechange=function(){
if (xmlHttp.readyState==4 && xmlHttp.status==200)
    {
    document.getElementById('ReloadDIV').innerHTML=xmlHttp.responseText;
    setTimeout('Ajax()',10000);
    }
    }

readyState = 4 means request is finished and response is ready and the status = 200 is an OK response from the server


"I want to write a greasemonkey script that reloads every 10 sec. the same div of the same page."

This cannot be done like your trying to do it xmlHttp.open only works with valid urls. What you probably would want to do is call the page, scrape it and grab the elements you want and then replace the div.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜