How to send json object from controller to html template in node.js? -


hi new node.js please problem.

this controller have search function called function server.js captured json object api.

and want send object html page written code below.

i.e, res.render('display',....) gives error.i.e undefined not function.

please me how redirect html template json object controller in node.js?

var storejsondata;  exports.search = function(req,res){    var callback = function(error, data) {     if (error) {      // error handling here      console.log(error);     } else {     // success handling here      storejsondata = json.parse(data);      res.render('display', {       jsondata: storejsondata     }); } 

i believe you're not setting express correctly template engine.

assuming you're using express , jade passing values (or context) template follows;

var express = require('express'); var app = express();  // assuming search controller in controllers/search var searchctrl = require('./controllers/search');  app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.get('/search', searchctrl); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -