Error while capturing existing data

Asked

Viewed 20 times

0

I have two AJAX services. In one of them I search the user data in a JSON that an API returns to me, I parse it and ask it to insert a certain data for me in a tag

. The code is this:

if(xhr.status == 200){

    console.log(xhr.responseText);

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

    let ultimaAulaAcessada = "";
    ultimaAulaAcessada += ultimaAula.ultimaAulaAcessada;
    document.querySelector("#ultima-aula").innerHTML = ultimaAulaAcessada;

}

Well, he takes the id of the last class and inserts it for me in the last class. So far so good. He inserts this tag

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

Now I have another service that needs to recover this data to perform another action for me.

I do his AJAX and let him know that in #ultima-class is the id he needs to run the service, but he says that the field is empty and is not, because I see the id being displayed on the screen. What can it be?

  • You are not getting the data that is in "last-class"?

  • This, it displays to me on the screen, IE, shows there in the <p> tag the id that the ajax entered by innerHtml, but when I go to take the data it says that it is empty

  • If for example, I take the same tag and enter an id by hand, it performs the service. But when it comes from ajax it does not perform

  • What do you want? https://jsfiddle.net/a9m18dww/

  • How’s the code that picks up the content of the id #last-class?

  • Solved the problem. I saw that you asked another question and ignored this.

  • So I actually solved it, but not in the expected way. I put a setTimeout in the second code with a delay second and it worked

Show 2 more comments
No answers

Browser other questions tagged

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