i want to write 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:
readyState = 4 means request is finished and response is ready and the status = 200 is an OK response from the server