I'm using this on server side:
app.get('/getdata', function(request, response) {
client.query("SELECT time, name, assembly FROM timings order by time limit 10", function(err, results) {
console.log(results.rows[0]);
if (err) {
throw err;
}
}
//here i want to do something to send results to my html page
});
And this on client side html page
<form action="/getdata" method="get">
<input type="submit" value="Submit" ></input>
</form>
Also, help me with how I can display data on the same HTML page. And where i have to place my code because i'm new to nodejs.
Your code could look something like this:
app.get('/getdata', function(request, response) {
client.query("SELECT time, name, assembly FROM timings order by time limit 10", function(err, results) {
if (err) {
throw err;
}
response.send(results.rows); // assumes 'results.rows' can be serialized to JSON
});
});
You can retrieve that information from your HTML page using an AJAX-request. Let's assume you use jQuery (error handling not included):
$.getJSON('/getdata', function(response) {
// do something with the response, which should be the same as 'results.rows' above
});