Partially change a page via Javascript [duplicate]

0

I wanted this code to only update one part of the site and not the whole site.

Because when I run the function in a div, it updates the whole site.

<script type="text/javascript">
function Ajax(){
  var xmlHttp;
  try { xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari }
  catch (e){
    try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer }
    catch (e){
      try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e){
        alert("No AJAX!?");
        return false;
      }
    }
  }

  xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
      document.getElementById('ReloadThis').innerHTML=xmlHttp.responseText;
      setTimeout('Ajax()',10);
    }
  }
  xmlHttp.open("GET","index.php",true); // aqui configuramos o arquivo
  xmlHttp.send(null);
}

window.onload=function(){
  setTimeout('Ajax()',10); // aqui o tempo entre uma atualização e outra
}
</script>
    
asked by anonymous 13.02.2016 / 22:44

1 answer

-2

I think it's because you put the function inside the onload of the page. Try to put inside a setInterval without the onload, like this:

var interval = setInterval (Ajax (), 10);

    
14.02.2016 / 04:35