jQuery template issue with JSON data -


i'm using jquery templating taking json data create table. code working fine. when try create function around code , pass json data i'm getting ajax request, shows values in console not in table. working code dummy data is:

var json = [{"class":12,"marks":"500","marks1":"200","marks2":"300"},{"class":11,"marks":"200","marks1":"300","marks2":"400"}]  $.template('klist','<tr title="${class}"><td>${marks}</td><td>${marks1}</td><td>${marks2}</td></tr>');    for(var i=0; i<json.length; i++){        $.tmpl('klist',json[i]).appendto("#table1") } 

here code i'm warping upper code in function , passing json data parameter shows values in console when print console.log(json) not filling table. json parameter having same json data in above code.

function datatable(json){     console.log(json); // here json values appearing in console     $.template('klist','<tr title="${class}"><td>${marks}</td><td>${marks1}</td><td>${marks2}</td></tr>');        for(var i=0; i<json.length; i++){            $.tmpl('klist',json[i]).appendto("#table1")     } } 

please me out because don't know whats wrong in code. in advance.

your json parameter string. should convert object, using $.parsejson(json).

take @ this conversion detail.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -