How do I create an HTML table, in jQuery, with JSON data?

Create HTML table from JSON data with JQUERY or Javascript or ANYTHING

  • Possible Duplicate: http://stackoverflow.com/questions/1051061/convert-json-array-to-an-html-table-in-jquery I'm trying desperately to figure out out to make this table... I have 3 fields i need to be in the same <td> and another field by itself in a <td> I am successfully getting the data with JSON to my page with this code. $.ajax({ url: 'code.php', async: false, dataType: 'json', success: function (json) { window.upc = json.upc; window.img_name = json.img_name; window.quantity = json.quantity; window.description = json.description; } }); how can i get this data to be formatted like i want? |TEXT|image| |TEXT|goes| |TEXT|here| Thanks.

  • Answer:

    Check out: http://icanhazjs.com/ STEP 1. - DEFINE YOUR TEMPLATE <script id="template" type="text/html"> <table> <tr> <td>{{quantity}}{{description}}</td><td>{{img_name}}</td> </tr> </table> </script> STEP 2. - RETRIEVE YOUR POPULATED TEMPLATE: $.ajax({ url: 'code.php', async: false, dataType: 'json', success: function (json) { var yourTable = ich.template(json) } }); You can append the variable yourTable to any element on the page.

Devin Prejean at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.