Help in Method GET in a form

Hi all, again,

I’m in a block state because i know how i want but can’t seem to do it.

I have some data in mysql database and i want to populate a table with it.
In the HTML i have, dont know if it is right or not, a form method=“GET” with a table inside but i dont know how to do the app.get in express in order to populate the table with the data.

Thanks in advance.

Do you have your code on github or something?

Sorry but no, i’ve tried once to deposit the code in git but it got an error of uploading too many files…never got that error.

But the app.get is blocking me and with it i can’t advance. I have an app.post working saving in the Database, but getting the info from it and populate a table in html is other matter…

so, you want to populate the form with data from the get-request?

this question is NOT about “sending info, from the form, to the database” , correct?

i think this might help you. its all about get request in express:
https://expressjs.com/en/api.html#app.get

so, perhaps this line:

app.get(’/’, function (req, res) {
res.send({ keyname: [arraystuff] });
});

Did you use .gitignore?

hmm, i dont know how. Never had a problem uploading my code into git. I presume is something about the node.

BenGitter, i’ve did it. It’s in the git.

The html file with the table is in pages/ver_plan.html. All the code in JS is in the index.js

Thanks

Seemingly not.

@RicardoJFN Forms are only used to send data to a server, not to GET data. GET and POST only differ in the way they send data to the server. HTML form method Attribute

Instead of using a form, you will need to make a GET request with JS. The returning data should then be placed inside the DOM via the JS.

Also, it is standard to .gitignore the node_modules folder.

Hmm maybe i wasn’t clear in my doubts.

I have the data already saved in my DataBase and what i wanted to do is retrieve that data, from the DB, and populate a Table in html with it.

I will check the link and the post from @ronstarcool

Update:

I did it, i can retrieve the data from the database but i can’t seem to show one type of data with multiple records.

I did this:

app.get(’/ver_plan.html’, function(req, res){

connection.query("select * from planeamento", function(err, result){
    if(err)
        throw err;
    
    
    for(var i = 0; i!= result.length; i++){
        res.send(result[i].TipoDespesa);    
    }
        
});

});

it sends the first record and crashes on the others…

res.send() also closes the request. So you could build an array in the for loop and after that send the array.

Thanks for the tip. It is working. Now i just have to try to populate a table or something in order to appear in the page that it is supposed to appear and not in a blank page.