0

I wrote a javascript(nodejs+express) program to download a html document from a given url. I converted into a DOM object using parse5, jsdom, cherrio(only one). Now I need to send the response(the DOM object) to an ajax call. But when I try

var document = jsdom(data); //can use any of these three

var $ = cheerio.load(data);

var document3 = parse5.parse(data);

return res.send({'data':document3});

It gives an error 'converting circular structure to json', which is obvious because I'm trying to convert a DOM object to JSON.

My requirement is to parse the HTML and send the DOM as response because I need to use the DOM on client side. What should be approach?

diiN__________
  • 7,393
  • 6
  • 42
  • 69
Puneet
  • 654
  • 1
  • 8
  • 16
  • Have you tried just send the DOM (assume you have done some process on it) as a string and convert the DOM string back to a DOM on client side? Obviously Json won't work for the DOM obj. – TypingPanda Sep 06 '16 at 08:17

1 Answers1

0

Have you tried just send the DOM (assume you have done some process on it) as a string and convert the DOM string back to a DOM on client side? Obviously Json won't work for the DOM obj.

TypingPanda
  • 1,607
  • 3
  • 19
  • 32