Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!