0

my function "fus.listjson" that generate json data i wants to send specific html page.So i perform such operation, how can i solve this problem.

app.get('/list/json',fus.listjson);

currently i used socket connection. I does not want to use socket connection any other methods in node.js to handle this task.

socket.emit('ffusdata', { fusdata: fus.listjson});

plz help how do i go above this. thank's in advance

2
  • is that a websocket? are you using socket.io? what's the problem with your approach? what's your client's code? Commented Mar 20, 2014 at 11:27
  • when i using socket.io the html page received data from socket was blinking. I work on realtime data, so i want to received the data without blinking the page ..... Commented Mar 20, 2014 at 11:33

2 Answers 2

3

You want to render the JSON as part of a HTML page with other content? You're going to need a template engine with your express application.

EJS is decent (https://github.com/visionmedia/ejs) as is Jade. I've included a sample of EJS below.

app.get('/', function(req, res) {
  res.render('xyz', {
    jsondata: YOUR_JSON
  });
});

// xyz.ejs
<% if (jsondata) { %>
  <pre><%= jsondata %></pre>
<% } %>
Sign up to request clarification or add additional context in comments.

Comments

0

I assume you are using express, since you have app.get. In that case just use the json method on the response object:

app.get("/list/json", function(req, res) {
    res.json(fus.listjson);
});

2 Comments

my above method "app.get('/list/json',fus.listjson);" return json data on web when i typing url "/list/json" on web browser...
i want to send that json data on specific html page like xyz.html

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.