Advertisement
nubilfi

Delegate event - dataset

Jun 13th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var feed = '';
  2. for (var j = 0; j < feedItem.length; j++) {
  3.   feed += '<a href="#" class="list-group-item detail-item" data-id="feedItem[j]._id">Testing</a>';
  4. }
  5. $('#listFeeds').html(feed);
  6.  
  7. $(document).on('click', 'a.detail-item', function (event) {
  8.       event.preventDefault();
  9.  
  10.       var id = $(this).data('id');      // Tampung nilai dari dataset
  11.  
  12.       $.ajax({
  13.          type: "GET",
  14.          dataType: "json",
  15.          url: "http://localhost:3000/pickitem/"+id+"/detail", // Nilai variable id malah jadi string "feedItem[j]._id"
  16.          success: function(data) {
  17.            console.log(data);
  18.          }
  19.       });
  20.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement