how to print json array in html return by node.js -
i return array node.js reading xml content txt file , store in array send html page using ajax method how task.
xml2js = require('xml2js'); fs = require('fs'); var arr={}; var parser = new xml2js.parser(); fs.readfile('d:/test.txt', function(err, data) { parser.parsestring(data, function (err, result) { arr=result.cluster.array[0].string; }); }); app.get('/test', function(req, res, next) { res.json({ message: arr }); //passing array data });
how display in html page current used. whole data in console log not able display in html page message undefined :
$.ajax({ url: '/test', complete: function(data) { json.stringify(data); console.log(data.message); // document.write(data.message); for(i=0;i<data.length;i++) { document.write(data.message[i].val); $('#did').append('<h1>'+data.message[i].name+'</h1>'); } }
use readstream, , stream httpresponse
stream = fs.createreadstream "path/to/file.json" stream.pipe(res)
Comments
Post a Comment