Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Can someone please tell me why my ajax response is nullifying?

Let's say I have some code similar to this:

let thing = null;
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
  thing = JSON.parse(this.responseText);
}
xhttp.open("GET", url);
xhttp.send();

console.log(thing.propertyOfThing);

This is not exactly my code, but it works for the purpose of this question. Anyway, the GET request works fine and thing gets set to the JSON object. However, when the code gets to the console.log statement, suddenly thing is null again and I get a NullPointerException (or at least the JavaScript equivalent of that) whenever I try to use properties of the JSON object.

Does anyone know why this is the case?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda