2
Hello, recently I’m studying a little web programming (I’m very early) and I ended up falling into Node.js, I’m finding everything amazing I’m just having a certain problem, I want to access mysql return a query by Node and pass this JSON to an array in javascript inside ejs (html) front-end, but I’m not getting it, so what am I doing wrong? Follow the BD access code (Obs the connection to the bank is working so I will not insert it here)
connection.query('select * from marcadores', function(err, results){
res.render('map',{lista : results});
});
and follow the code inside the javascript (front)
var locations = Array();
<%for(i = 0; i<lista.lenght;i++){%>
locations.push(<%lista[i].id%>);
locations.push(<%lista[i].titulo%>);
locations.push(<%lista[i].latitude%>);
locations.push(<%lista[i].longitude%>);
You can put an example of how you want HTML to come out?
– Sergio
This application I’m testing is with Google Maps, the idea is to pass the information of the vector to an object inside the Object Map and display later
– Ramon Fernandes
So you want to pass
{lista : results}
for a Javascript variable, that’s it?– Sergio
Yes, I don’t know how to go from the database query (Node.js) to the javascript that is in my html file
– Ramon Fernandes
My answer helped?
– Sergio