0

I am trying to create JSON template using JS here is my code.For some reason it doesn't display any result.Can some one please check what is the issue

<html>

  <head>

    <script type="text/javascript"src=""http://jsontemplate.googlecode.com/svn/trunk/javascript/json-template.js"">
    </script>
    <script type="text/javascript">
function write() {
      var t = jsontemplate.Template("{# This is a comment and will be removed from the output.}\n\n{.section products}\n  <h2>Products for Dove</h2>\n\n  <table width=\"100%\">\n  {.repeated section products}\n    <tr><td>{Product Name}</td>\n</tr>\n  {.end}\n  </table>\n{.or}\n  <p><em>(No page content matches)</em></p>\n{.end}\n");

var s = t.expand({

        "products": [{
        "Product Name": "dove moisturiser"


    },


    {
        "Product Name": "Deodrant"

    }]
});
document.getElementById("replace").innerHTML = s;

} </script> </head> <body onload="write();"> <h4>This is for test.</h4> <div id="replace"></div> </body> </html>

  • It seems you have a multiline string, which are not supported in this form in JS. The `src` attribute of the script is wrong too (`src=""http://jsontemplate.googlecode.com/svn/trunk/javascript/json-template.js""`), you need to have only on quotation mark at the beginning and end. Have a look at http://stackoverflow.com/q/805107/218196. To learn how to debug JavaScript, have a look at http://www.netmagazine.com/tutorials/javascript-debugging-beginners. – Felix Kling Mar 13 '13 at 19:31
  • Take your javascript code, open a browser to http://jsfiddle.net/ paste that code in and click the JSHint button. – Mark Schultheiss Mar 13 '13 at 19:34
  • I have rectified above errors .and i guess script is triggered but not displaying JSON..any reason.code is updated as above.it is valid in jsfiddle.net – user2167006 Mar 13 '13 at 20:31

0 Answers0