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

90
Views
POST Request adding table row to SQL DB without data

I'm sending a rq to my psql that is working because it is updating my db with an extra row on every click (in the right table too). The problem is, it isn't adding in data to that table. I'm trying to post the data from the current cell I'm in, in the for loop, so in this case: newCell. The code is faulty when I try to JSON.stringify the data. I've tried: JSON.stringify(e.value.innerText) and JSON.stringify(e.target.name) but when I check the req.body on the server side, it says it's an empty object (no data).

Here's my client side:

openFileButton.onclick = async() => {
    const dirHandle = await window.showDirectoryPicker();

        for await (const entry of dirHandle.values()) {
            let color = false;
            if (entry.name.slice(entry.name.length-3) === ' BR' || entry.name.slice(entry.name.length-3) === 'DVD') {
                var name = entry.name;
                var newRow = table.insertRow();
                var newCell = newRow.insertCell();
                var newText = document.createTextNode(name.substring(0,name.length-5));
                newCell.className = 'cell';
                var secondCell = newRow.insertCell();
                var secondText = document.createTextNode(name.slice(name.length - 3));
                newCell.onclick = async function(e) {
                    if (!color) { 
                        e.target.style.backgroundImage = 'linear-gradient(to right, black, greenyellow)';
                        e.target.style.color = 'white';
                        const response = await fetch("http://localhost:5000/movies", {
                            method: "POST",
                            headers: {"Content-type":"application/json"},
                            body: JSON.stringify(e.target)
                        });
                        // console.log(e.target);
                        color = true;
                    } else {
                        e.target.style.backgroundImage = 'linear-gradient(to right, black, red)';
                        color = false;
                    }
                }
                newCell.appendChild(newText);
                secondCell.appendChild(secondText);
                console.log(entry)
            } else {
                continue;
            }
        }
}

My server side works:

app.post('/movies', async (req,res) => {
    try {
        const name = req.body;
        console.log(req.body);
        const newMovie = await pool.query("INSERT INTO movies (name) VALUES($1) RETURNING *", [name]);

        res.json(newMovie.rows[0]);
    } catch(err) {
        console.error(err.message)
    }
})

But console.log(req.body) returns {}, the post request didn't send any data.

Anyone know the issue?

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