parsing - How can i JSON.stringify some JSON and place into html then parse it in nodejs server by JSON.parse -
i want stringify json first in html file using javascript place in html, after i'm parsing html using cheeriojs & request in nodejs , here want json json.parse() method, how can that.
here html code:
<script type="text/javascript"> //stringify json var nav = { component : "navbar", container_class : "div", menu_link_color: "blue", hover_color: "white" } var str = json.stringify(nav); document.getelementbyid('edit').innerhtml=str; </script> </head> <body> <div class="wp" id="edit"> </div> </body> </html>
here nodejs code parse html stringified json:
var url = "http://localhost/test/test.html"; request(url,function(err,res,body){ var $ = cheerio.load(body); $('.wp').filter(function(){ var navbar = $(this); var navtext = navbar.text(); var textjson = json.parse(navtext); console.log(textjson); }); })
i have done job following these steps:
- built json object in javascript
- json.stringify() json object
- place json string html , hide display
- then have parse json string in nodejs using cheeriojs
- in node server have json.parse() string , convert json object need html.
Comments
Post a Comment