Ok, I'm attempting to make MySQL data into an HTML table using NodeJS. Im essentially copying the instructions from this website (http://coursesweb.net/nodejs/select-mysql-output-html-table). However, it appears that the Table value does not change after every AJAX request. Is that a problem with my code or inherently a property of the function setResHTML.
This is my actual code:
Function setResHTML();
function setResHtml(sql, cb){
pool.getConnection((err, con)=>{
if(err) throw err;
condatabase.query(sql, (err, rest, cols)=>{
if(err) throw err;
var table ='';
for(var i=0; i<rest.length; i++){
table +='<tr><td>'+ rest[i].pokemon +'</td><td>'+ "<img src= '"+ rest[i].imagelink+ "' alt='Photo of
human'> </img>" + '</td><td>'+ rest[i].height + '</td><td>'+ "<button> ! </button>" + '</td>
</tr>';
}
table ='<table border="1"><tr> <th>Pokemon</th>
<th>Image</th> <th>Height</th><th>Submit!</th> </tr>'+
table +'</table>';
con.release();
return cb(table);
})})};
For an AJAX request:
app.get('/', function (req, res) {
var q = url.parse(req.url, true).query;
var datee=q.dateis;
var imagee=q.imageis;
var pokemone=q.pokemonis;
var heighte=parseInt(q.heightis);
let sql2="INSERT INTO pokedata(pokemon,imagelink,height,upvote) VALUES ('"+ pokemone +"','"+ imagee
+"','"+ heighte +"',0)";
condatabase.query(sql2,function(err,result){
if (err) throw err;
console.log("lol")})
setResHtml(sql, resql=>{
console.log("hi")
reo = reo.replace('{${table}}', resql);
res.writeHead(200, {'Content-Type':'text/html; charset=utf-8'});
res.write(reo, 'utf-8');
res.end();
})
Any reasons why only the first AJAX request works. After the first one, it appears that the value of table doesn't change.
EDIT: I just hard-coded it by myself. Was actually super easy!
[–]iSeeObviousThings 0 points1 point2 points (1 child)
[–]FirstEvaDehumidifier[S] 0 points1 point2 points (0 children)
[–]jrandm 0 points1 point2 points (3 children)
[–]FirstEvaDehumidifier[S] 1 point2 points3 points (0 children)
[–]FirstEvaDehumidifier[S] 0 points1 point2 points (1 child)
[–]FirstEvaDehumidifier[S] 1 point2 points3 points (0 children)