Reputation: 25
when i try to access my object {{result}} in my view, which i send from my express js server, its only showing [object][object] is there anyone know how to get its value in JSON format?
this is my html code
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<div class="container" id="chart_div"></div>
</body>
<script type="text/javascript">
console.log({{result}});
</script>
and this is my server code
const express = require('express');
var session = require('express-session');
const mysql = require('mysql');
const connection = require('../db.js');
const app = express();
app.use(session({
secret: 'fffdfee',
resave: false,
saveUninitialized: false,
}));
module.exports = {
getGraphQuis: function(req, res){
connection.query('select questionnaireresult.*, questionnaire .typequestionnaire from questionnaire inner join questionnaireresult on questionnaire.id = questionnaire.idquestionnaire where?', {
idquestionnaire: req.params.id,
}, function(err, rows, fields){
if(rows[0]){
res.render('stakeholder/grafik-result', {result: rows});
}else {
res.render('stakeholder/alert')
}
});
},
}
Upvotes: 0
Views: 97
Reputation: 4202
You can use JSON.stringify({{ result }})
This will output the value into a JSON string
var obj = {a: 1}
document.getElementById('1').innerHTML = obj
document.getElementById('2').innerHTML = JSON.stringify(obj)
<div id="1"></div>
<div id="2"></div>
Upvotes: 1