Condition the selection of an ID

0

I have the following AJAX function:

function exibeUltimaAula(){


  let montaAula = {

    idUsuario: document.querySelector('#id').textContent,
    token: document.querySelector('#token').textContent,
    id: document.querySelector('#ultima-aula').textContent
  };

  var xhr = new XMLHttpRequest();
  var variavel = document.querySelector('#token-servico').innerHTML;

  xhr.open("POST", "http://54.233.209.248:8080/rest/classes/findById", true);
  xhr.setRequestHeader("Content-type", "application/json");
  xhr.setRequestHeader("Authorization", "Bearer " + variavel);
  xhr.addEventListener("load", function(){

    if(xhr.status == 200){

      console.log(xhr.responseText);

      let aula = xhr.responseText;
      aula = JSON.parse(aula);

      let video = "";
      video += aula.video;
      document.querySelector("#video-aula").innerHTML = video;

      let descricao = "";
      descricao += aula.descricao;
      document.querySelector("#aula-descricao").innerHTML = descricao;

    }

    if(xhr.status =500){
      console.log(xhr.responseText);
    }
  });
  xhr.send(JSON.stringify(montaAula));
}

  setTimeout(exibeUltimaAula, 1000);

This function inserts an ID in tag 1 which is:

<p id="ultima-aula"></p>

However, in another situation in the system, I need this ID to come to me via GET, so I enter this id in the second tag:

Tag 2 <p><?=$aula?></p>

I'm having a conflict about this, I wonder if there is any place in this ajax where I can make a condition.

The condition would be as follows:

If the ID comes from the URL I use the tag 2, if it does not come from the URL I use the tag 1.

Is there a way to do this?

    
asked by anonymous 11.05.2018 / 00:09

0 answers