I have a variable that contain all the subject names that are the column names of a table.Now i got all column names in a variable.Use this variable name in select statement.
Ajax
success:function(result) {
console.log(result);
var tab = '';
for(var i=0;i<result.length;i++) {
tab += "<div class='col-xs-12 mrgntTB3'> <div class='row'>";
tab += "<div class='col-xs-2 blk-ht1'><span class='tbRrptsstdNames'>" + result[i]["student_name"]+ "</span></div>";
tab +=" <div class='col-ds-1'><span class='badge scrore scrore-pt bg-aqua'>"+ result[i]["english"]+"</span></div>";
tab +="</div></div><div class='clearfix'></div>"
}
$("#subjectNames").append(tab);
$("#subjectNames").append(tab);
}
How can i take each subject names in ajax success like student name
You can split and loop them like the following.
var tab = '';
var nameArray = [];
var keys = [];
for(var k in result[0]) {
keys.push(k);
}
for(var i=0;i<result.length;i++) {
tab += "<div class='col-xs-12 mrgntTB3'> <div class='row'>";
tab += "<div class='col-xs-2 blk-ht1'>";
tab += "<span class='tbRrptsstdNames'>" + result[i]["student_name"] + "</span><div>"
for(j = 1; j < keys.length; j++){
tab += "<div class='col-xs-2 blk-ht1'>";
tab += "<span class='tbRrptsstdNames'>" + result[i][keys[j]] + "</span><div>"
}
tab += "</div></div><div class='clearfix'></div> ";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.