how do I pass objects from server to html?
I have my nodejs code here below that I stripped off details to keep it simple.
nodejs.js
const bodyParser = require('body-parser');
const urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use(bodyParser.json());
app.post('/',urlencodedParser, function(req, res) {
Object = new Class();
res.status(200).json(Object);
});
Here is my js code called by html.
myjs.js
function fetcher() {
fetch('/',
{
method: "POST",
body: JSON.stringify({"name": document.getElementById("name").value}),
headers: { "Content-Type": "application/json" }
}
)
.then(function(response) {
return response.json();
})
.then(function(Obj) {
console.log(obj.func());
});
}