0

I have a node.js server, with express, which contains a POST which is called when a form is filled in to return data from twitter. Now the POST works as expected and currently I am just using:

res.status('Tweets').send(tweettxt);

With tweettxt being an object of all the tweets returned. Now this just creates a blank page which displays this object, but is there a way to dynamically add to the existing HTML page with the form this data?

2 Answers 2

3

I assume you are using ejs templating engine as you have mentioned html pages.Which uses tags to display data received from server. you can display the data by

res.render('htmlPage',{
  tweettxt:tweettxt
});

In the htmlPage.ejs you can use tags like <%= tweettxt %>this to display data.

If you are using ajax to submit the form.You can use jquery to loop through the twitter response object and display it in the html pages dynamically as you stated.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use ajax to POST then handle the result or render the page after post.

The easiest way to render to use handlebar on the server side.

res.header('Content-Type', 'text/html; charset=utf-8');
res.status(200).send(
    Handlebars.compile(
        fs.readFileSync(
            path.join(
                __dirname,
                'template.html'
            )
        ).toString('utf-8')
    )(tweettxt)
);

template.html:

<html>
<body>
</body>
</html>

http://handlebarsjs.com/#getting-started

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.