1

I am creating a like button for each post using express with ejs. When I am using form, the entire page is getting refreshed and it defeats the whole purpose. When I am using button, the I am unable to extract the info like id without Dom. Can anyone please recommend what can I use to track the button activity every time its pressed since Dom doesn't work in express. There will be lots of button, one with every post. Every post is dynamically created with inputs from user, just like twitter. tweets with like. If I can keep track of who clicked the like button, it would result in keeping track of all likes dislikes to each post. This is my first project, kindly help.

This is dynamic format I am using:

          <% for(let i=0;i<tweet.length;i++){ %>
            <div class="tweets">
              <span> <%= tweet[i].name %></span><br>
              <span> <%= tweet[i].data %></span><br>
              <button type="submit" class="" name="like" id="<%= 'thisis'+ tweet[i].id%>"><i class="fa fa-thumbs-up" aria-hidden="true"></i></button>
            </div>
          <%} %>

I am giving button same Id as tweet so I can know which one is pressed.

Thank you

1 Answers1

1

Try using something like ajax to perform a post request without refreshing the page or 'leaving' the current page.

Ajax tutorial for post and get

oriel9p
  • 298
  • 2
  • 5