如何在没有Dom的情况下提取express中的id名称等按钮信息
我正在使用 Express 和 ejs 为每个帖子创建一个“赞”按钮。当我使用表单时,整个页面都会刷新,这违背了整个目的。当我使用按钮时,如果没有 Dom,我无法提取 id 等信息。任何人都可以推荐我可以使用什么来跟踪每次按下按钮时的活动,因为 Dom 不能在 Express 中工作。会有很多按钮,每个帖子都有一个。每个帖子都是根据用户的输入动态创建的,就像 Twitter 一样。推文喜欢。如果我可以跟踪谁点击了“喜欢”按钮,那么就可以跟踪每个帖子的所有喜欢和不喜欢。这是我的第一个项目,请帮助。
这是我正在使用的动态格式:
<% 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>
<%} %>
我给按钮提供了与推文相同的 ID,这样我就可以知道按下了哪一个。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 ajax 之类的东西来执行 post 请求,而无需刷新页面或“离开”当前页面。
Ajax 发布和获取教程
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