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 the tag 1 which is:
<p id="ultima-aula"></p>
However, in another system situation, I need this ID to come to me via GET, so I insert this id in the second tag:
Tag 2 <p><?=$aula?></p>
I’m having a conflict about that, I wonder if there’s 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.
I wonder if there’s a way?
I couldn’t see in the code where the function inserts the id as mentioned in the question.
– Sam
id: Document.querySelector('#last-class'). textContent this line, insert this line <p id="last-class"></p>
– Francis Vagner da Luz