我为每个循环构建了一个从数据库中拉回几行的循环。它拉出的每一行都有一个链接,以及一个隐藏的输入框,其值为 posting_id。此链接在某种程度上类似于 facebook 上的点赞按钮。隐藏的输入框只存储了posting_id。当您单击“喜欢”链接时,它会将 posting_id 发送到一个 jQuery 页面并 ping 回一个名为 community 的页面,告诉它用户已经“喜欢”了该帖子。
这就是问题所在
我拉了几行,当您单击“喜欢”按钮时,似乎只有被拉的第一行实际上正在将数据发送到 jQuery 页面。如果我单击除顶部按钮之外的任何其他“喜欢”按钮,它将根本不起作用。
jQuery 页面
$('.bump_link').click(function(){
var posting_id = $('.posting_id').val();
$.post("community.php", {
posting_id: posting_id
});
alert(posting_id);
$(this).toggleClass("bumped");
});
Foreach 循环
foreach ($result as $value) {
$group_postings .= '
<input type="text" class="posting_id" value="'.$value['posting_id'].'">
<div id="bump_icon" class="bump_link"></div>
<span id="counter"></span>
';
}
我希望我已经把这个问题说清楚了,它曾经而且很难解释。