Can not set property 'innerHTML' of null

0

When my code is executed in ajax it gives this error:

  

Uncaught TypeError: Can not set property 'innerHTML' of null

     

at XMLHttpRequest.req.onreadystatechange ( link @ inicio.php: 57      home.php: 57 Uncaught TypeError: Can not set property 'innerHTML' of null (...) req.onreadystatechange @ start.php: 57

This is my code:

<script type="text/javascript">
    function ajax(){
      var req = new XMLHttpRequest();

      req.onreadystatechange = function(){
        if (req.readyState == 4 && req.status == 200){
          document.getElementById('complemento').innerHTML = req.responseText;
        }
      }
      req.open('GET','header.php',true);
      req.send();
    }

    //linea que hace que se refresque la página cada segundo.
    setInterval(function(){ajax();}, 60000);
  </script>

    <script type="text/javascript">
    function ajax2(){
      var req = new XMLHttpRequest();

      req.onreadystatechange = function(){
        if (req.readyState == 4 && req.status == 200){
          document.getElementById('Amigos').innerHTML = req.responseText;
        }
      }
      req.open('GET','Amistades.php',true);
      req.send();
    }

    //linea que hace que se refresque la página cada segundo.
    setInterval(function(){ajax3();}, 1000);
</script>

  <script type="text/javascript">
   ' function ajax3(){
      var req = new XMLHttpRequest();'

      req.onreadystatechange = function(){
        if (req.readyState == 4 && req.status == 200){
          document.getElementById('publicacion').innerHTML = req.responseText;
        }
      }
      req.open('GET','publicacion.php',true);
      req.send();
    }

    //linea que hace que se refresque la página cada segundo.
    setInterval(function(){ajax2();}, 1000);
  </script>

How could I solve it?

    
asked by Carlos Saz 28.08.2017 в 05:39
source

0 answers