如何根据我的AJAX结果主动增加我的计数器?(How do I actively increment my counter based off of my AJAX results?)

编程入门 行业动态 更新时间:2024-10-24 00:27:22
如何根据我的AJAX结果主动增加我的计数器?(How do I actively increment my counter based off of my AJAX results?)

我正在进行我的第一个ajax项目的最后一步。 我做了一个竖起大拇指图标,当按下这个代码时,数据库中的一列将增加:

这是浏览页面上的HTML和JQUERY

<div id="comment_id">+1</div> <div id="thumb_thumb"> <?php $comment_id = $result['id'];?> <a class="myButtonLink" href="Profile_test.php?id=<?php echo $prof->id; ?>" id="<?php echo $comment_id; ?>">Vote Up!</a> </div> <script> $('.myButtonLink').click(function(e) { e.preventDefault(); var comment_id = $(this).attr('id'); $.ajax({ type: 'POST', url: 'thumbs.php', data: 'comment_id=' + comment_id, success: function(data) { alert(data); if(data.result == "error") { alert(data.msg); } else { $('#numvotes').html(data.msg); } } }); }); </script>

这里是它隐藏的PHP页面

<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/system/init.php'); // 1. CHECK AND SEE IF THE "$comment_id" IS VALID. I AM GOING TO RETREIVE THE VALUE OF THE $_POST BEING SENT FROM THE PHP PAGE THAT IS SENDING THE REQUEST /* QUERY TO CHECK $_POST DATA WITH: */ /* this is grabbing id that jquery sent over via post */ if(isset($_POST['comment_id'])) { /* making a variable out of the grabbed id */ $retreived_comment_id = $_POST['comment_id']; $query = "UPDATE `CysticAirwaves` SET `thumbsUp` = `thumbsUp` + 1 WHERE `id` = '" . $retreived_comment_id . "'"; $request = mysql_query($query,$connection) ; $result = mysql_fetch_array($request); } ?>

所以现在我只需要能够动态地让我的计数器工作,当一个拇指被点击并且指定的注释在db中被标记为加号

<div id="comment_id"> +1 //NEED TO MAKE THIS ACTUALLY COUNT </div>

提前致谢

I am on the final step of my first ajax project. I've made a thumbs up icon that when pressed increments a column in the database via this code:

HERE IS THE HTML AND JQUERY ON THE VIEWABLE PAGE

<div id="comment_id">+1</div> <div id="thumb_thumb"> <?php $comment_id = $result['id'];?> <a class="myButtonLink" href="Profile_test.php?id=<?php echo $prof->id; ?>" id="<?php echo $comment_id; ?>">Vote Up!</a> </div> <script> $('.myButtonLink').click(function(e) { e.preventDefault(); var comment_id = $(this).attr('id'); $.ajax({ type: 'POST', url: 'thumbs.php', data: 'comment_id=' + comment_id, success: function(data) { alert(data); if(data.result == "error") { alert(data.msg); } else { $('#numvotes').html(data.msg); } } }); }); </script>

HERE IS THE HIDDEN PHP PAGE IT IS SENT TO

<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/system/init.php'); // 1. CHECK AND SEE IF THE "$comment_id" IS VALID. I AM GOING TO RETREIVE THE VALUE OF THE $_POST BEING SENT FROM THE PHP PAGE THAT IS SENDING THE REQUEST /* QUERY TO CHECK $_POST DATA WITH: */ /* this is grabbing id that jquery sent over via post */ if(isset($_POST['comment_id'])) { /* making a variable out of the grabbed id */ $retreived_comment_id = $_POST['comment_id']; $query = "UPDATE `CysticAirwaves` SET `thumbsUp` = `thumbsUp` + 1 WHERE `id` = '" . $retreived_comment_id . "'"; $request = mysql_query($query,$connection) ; $result = mysql_fetch_array($request); } ?>

So now I just need to be able to dynamically have my counter work when a thumb is clicked and the specified comment is marked a plus one in the db

<div id="comment_id"> +1 //NEED TO MAKE THIS ACTUALLY COUNT </div>

Thanks in advance

最满意答案

var currentCount = $('#comment_id').text(); $('#comment_id').text(++currentCount); var currentCount = $('#comment_id').text(); $('#comment_id').text(++currentCount);

更多推荐

本文发布于:2023-08-06 19:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454969.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计数器   主动   actively   AJAX   based

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!