Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Cloud 9 ide post data to page not working

Cloud 9 ide post data to page not working

Problem

I am developing a small node.js application using express on Cloud 9 ide.

I have a static index.Html page and some routes defined. One of the routes is a post

app.post('/getJson', function (req, res) {
    jsonData = fetchData(req.body.selectpicker);
    res.render('index.html', '

tttt

'); });

As jade is not supported i just want to pass some html to the static page. Currently using

res.render('index.html', '

tttt

');

How can I render the html on the page?

Problem courtesy of: tjhack

Solution

The render() function of the response renders a view and returns the HTML. If you want to render pages, you need a rendering engine such as EJS or Jade. If you're using either of those rendering engines, you can pass the HTML like so:

res.render('index.html, {
  html: '

tttt

' });

Since Jade isn't supported (may I ask why?), this is how you'd insert the HTML fragment in EJS.


Solution courtesy of: hexacyanide

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Cloud 9 ide post data to page not working

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×