Syntaxerror: Unexpected Identifier 'Promise'

Asked

Viewed 184 times

-1

My page is giving the following error:

Syntaxerror: Unexpected Identifier 'Promise'. Expected either a closing ']' or a ',' following an array element.

This is my Javascript code:

var myVar;
    function atualizaCor() {
      for (var i = 1; i < 6; i++) {
        var mod = "mod"+i;
        document.getElementById(mod).className = 'bt0p';
      }
      for (var i = 1; i < 9; i++) {
        var rele = "rele"+i;
        document.getElementById(rele).className = 'bt0';
      }
      myVar = setInterval(getDados(), 5000);
    }

    const getDados = async () => {
        let url = 'http://192.168.1.144/statusG';
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = () => {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var data = xhttp.responseText;
                atualizaCorModulo(data);
            }
        }
        await xhttp.open("GET", url, true);
        await xhttp.send();
    }

    function atualizaCorModulo(data) {
      let arrParams = data.split('<br>');
      console.log(arrParams);
      let modulo1 = arrParams[0];
      let modulo2 = arrParams[1];
      let modulo3 = arrParams[2];
      let modulo4 = arrParams[3];
      let modulo5 = arrParams[4];
      console.log(modulo1);
      console.log(modulo2);
      console.log(modulo3);
      console.log(modulo4);
      console.log(modulo5);

        var modulo = document.getElementById("mod").value;
        console.log("valor modulo botao abre porta"+modulo);
        switch (modulo) {
          case "0":
            document.getElementById("mod1").className = 'bt1p';
            console.log("valor modulo1subtr"+ modulo1.substr(0,1));
            if ((parseInt(modulo)+1) == modulo1.substr(0,1)) {
              console.log("entrou condiçao");
              atualizaCorRele(modulo1);
            }
            break;
          case "1":
            document.getElementById("mod2").className = 'bt1p';
            if ((parseInt(modulo)+1) == modulo2.substr(0,1)) {
              atualizaCorRele(modulo2);
            }
            break;
          case "2":
            document.getElementById("mod3").className = 'bt1p';
            if ((parseInt(modulo)+1) == modulo3.substr(0,1)) {
              atualizaCorRele(modulo3);
            }
            break;
          case "3":
            document.getElementById("mod4").className = 'bt1p';
            if ((parseInt(modulo)+1) == modulo4.substr(0,1)) {
              atualizaCorRele(modulo4);
            }
            break;
          case "4":
            document.getElementById("mod5").className = 'bt1p';
            if ((parseInt(modulo)+1) == modulo5.substr(0,1)) {
              atualizaCorRele(modulo5);
            }
            break;
          default:
        }
    }
    function atualizaCorRele(modulo) {
      for (var i = 1; i < 9; i++) {
        if (modulo.substr(i+1,1) == 1) {
          var rele = "rele"+i;
          document.getElementById(rele).className = 'bt1';
        }
      }
    }

I’ve looked at it several times and it’s all right for me. Could someone help me identify where the error is to fix it?

I noticed that the getDados method is not working when it calls the second time, how do I call the same several times? because I need to pick up arguments on the route that the address is.

1 answer

0

try the following code for the Ajax request.

function getDados(){ let url = 'http://192.168.1.144/statusG'; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = () => { if (xhttp.readyState == 4 && xhttp.status == 200) { var data = xhttp.responseText; atualizaCorModulo(data); } } xhttp.open("GET", url, true); xhttp.send(); }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.