Guest User

Untitled

a guest
Aug 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using Jquery to get XML and put into html table
  2. <aside id="shows"class="aside shadow">
  3. <div class="text" id="table">
  4. <div class="more low"> MORE SHOWS </div>
  5. <div class="less"> LESS SHOWS </div>
  6. </div>
  7. </aside>
  8.  
  9. function showData() {
  10. $.ajax({
  11. type: "GET",
  12. url: "shows.xml",
  13. dataType: "xml",
  14. success: function getShows(a) {
  15. $('#table').append('<h2>SHOWS</h2>');
  16. $('#table').append('<table>');
  17.  
  18. $(a).find('show').each(function(){
  19. var $show = $(this);
  20. var date = $show.find('date').text();
  21. var place = $show.find('place').text();
  22. var location = $show.find('location').text();
  23. var time = $show.find('time').text();
  24.  
  25. var html = '<tr><td class="bold">' + date + '</td><td class="hide">' + place + '</td><td>' + location + '</td><td class="bold">' + time + '</td></tr></table>';
  26.  
  27. $('<table>').append(html);
  28.  
  29. });
  30. }
  31. });
  32. }
  33.  
  34. <shows>
  35. <show>
  36. <date>9/8</date>
  37. <place>Toads Place</place>
  38. <location>New Haven, CT</location>
  39. <time>9PM</time>
  40. </show>
  41.  
  42. </shows>
  43.  
  44. url: "shows.xml",
  45.  
  46. $.ajax({
  47. type: "GET",
  48. url: "shows.xml",
  49. dataType: "xml",
  50. success: function(xml){
  51. $('#table').append('<h2>SHOWS</h2>');
  52. $('#table').append('<table id="show_table">');
  53. $(xml).find('show').each(function(){
  54. var $show = $(this);
  55. var date = $show.find('date').text();
  56. var place = $show.find('place').text();
  57. var location = $show.find('location').text();
  58. var time = $show.find('time').text();
  59. var html = '<tr><td class="bold">' + date + '</td><td class="hide">' + place + '</td><td>' + location + '</td><td class="bold">' + time + '</td></tr>';
  60. $('#show_table').append(html);
  61. });
  62. }
  63. });
Add Comment
Please, Sign In to add comment