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

248
Visualizações
injecting value into html using innerHTML returns undefined

So basically im trying to inject information that comes from my database (im using postgresSQL and node.js) into the webpage and i have confirmed that im getting the information i want right before trying to innerHTML however as soon as it goes to that codeline somehow it can't detect the value and inject undefined (i think) and im not sure why it's doing that.

here is the javascript for the html page im having problems :

window.onload = async function() {

    try {
        let courseId = sessionStorage.getItem("courseId");
        let course = await $.ajax({
            url: `/api/courses/${courseId}/classes`,
            method: "get",
            dataType: "json"
        });

        document.getElementById("course").innerHTML = course.cour_name;
    } catch (err) {
        console.log(err);
    }
}

I find it really weird since i have done it similarly with another page and it works fine.

here is the html for the page:

<html>

<head>
  <title>Express</title>
  <link rel="stylesheet" href="/stylesheets/style.css">
  <link rel="stylesheet" href="/stylesheets/courses.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js%22%3E</script>
  <script src = "./javascript/courseInfo.js"></script>
</head>

<body>
    <header id = "header">
    </header>
    <nav>
      <a href= "courses.html"><p>Back</p></a>
    </nav>
   <section>
     <main id="course">

     </main>
   </section>
</body>

</html>

I don't know why fills that field with undefined since when i stringify what the ajax return it shows that it has exactly what i need, one of those fields being the cour_name row.

I'd really appreciate if someone could help me with this problem and thank you for your time.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

if using chrome browser , try devtool debugger.

open the DevTool (e.g. press F12) then click on sources tab and locate your javascript file and put a breakpoint on the line this not working as expected. then reload the page and check the value of variables and executes the rest of the code line by line.

see this tutorial on how to use debugger https://developer.chrome.com/docs/devtools/javascript/

about 4 years ago · Juan Pablo Isaza Relatório
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