{"status":1,"message":"Get type list","result":[{"event_id":"1","event_title":"Tesla motors, inc, first quarter 2014\r\nfinancila result Q&A conference call","event_date_time":"2014-05-24 18:59:59"},{"event_id":"2","event_title":"Tesla motors, inc, first quarter 2014\r\nfinancila result Q&A conference call","event_date_time":"2014-05-31 16:54:57"},{"event_id":"3","event_title":"Tesla motors, inc, first quarter 2014\r\nfinancila result Q&A conference call","event_date_time":"2014-05-20 21:52:57"},{"event_id":"4","event_title":"Tesla motors, inc, first quarter 2014\r\nfinancila result Q&A conference call\r\n\r\nTesla motors, inc, first quarter 2014\r\nfinancila result Q&A conference call","event_date_time":"2014-05-01 19:49:44"}]}
...//my ajax code
success:function(data){
alert(data.result[0].event_title);
}
我从ajax得到这个响应结果,现在我想根据结果填充html表,我可以成功获取任何一行,但未能填满整个表。
如何将此结果附加到我的html表?
答案 0 :(得分:3)
试试这个,
for(var i=0;i<data.result;i++){
$("table tbody").append("<tr><td>"+ data.result[i].event_id +"</td><td>"+ data.result[i].event_title +"</td><td>"+ data.result[i].event_date_time +"</td></tr>")
}
答案 1 :(得分:3)
var tableString = "<table><tr><th>event_id</th><th>event_title</th><th>event_date_time</th></tr>";
for(var i = 0; i < data.result.length; i++)
{
tableString += "<tr>";
tableString += "<td>" + data.result[i].event_id + "</td>";
tableString += "<td>" + data.result[i].event_title + "</td>";
tableString += "<td>" + data.result[i].event_date_time + "</td>";
tableString += "</tr>";
}
tableString += "</table>";
$("#tableParentDivId").html(tableString);