javascript - Print json data in a table -


i have wrote following function i'm pretty sure there error. error when try execute chunck of code

typeerror: 'undefined' not function (evaluating 'callback.apply( obj[ ], args )') 

jquery function receive data json list correctlu

$("#result_times")     .find("tr")     .remove()     .end();  $("#result_times")     .find("table")     .each(data, function(){           $(this).append($("<tr>"));         $(this).append($("<td></td>")).text(data.airport_city_source);         $(this).append($("<td></td>")).text(data.airport_city_dest);         $(this).append($("<td></td>")).text((data.departure_date));         $(this).append($("<td></td>")).text((data.arrival_date));         $(this).append($("</tr>"));     }); 

this dom

<div id='result_times'>              <table>               </table>           </div> 

can suggest me wrong?

you running each() on each table, jquery expecting function first argument each, not data. calling text() on wrong element.

run each on data using $.each.

working example:

demo

$("#result_times")     .find("tr")     .remove()     .end();  var table = $('#result_times table');  $.each(data, function(){     table.append(         $('<tr></tr>').append(             $('<td></td>').text(this.airport_city_source),             $('<td></td>').text(this.airport_city_dest),             $('<td></td>').text(this.departure_date),             $('<td></td>').text(this.arrival_date)         )     ); }); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -