0

i return the array from node.js reading xml content from txt file and store in array send to html page using ajax method how do this 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 to display in html page current i used. But i get whole data in console log not able to display in html page get 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>');
      }
    }

1 Answer 1

0

use a ReadStream, and stream it into your httpResponse

    stream = fs.createReadStream "path/to/file.json"
    stream.pipe(res)
1
  • i read the data above define function but not able to display in another html page but i see data in console log. Commented Mar 13, 2014 at 4:29

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.