您现在的位置是:首页 > 电脑 > 

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

2025-07-19 09:00:21
如何根据我的AJAX结果主动增加我的计数器?(How do I actively increment my counter based off of my AJAX results?) 我正在进行我的第一个ajax项目的最后一步。 我做了一个竖起大拇指图标,当按下这个代码时,数据库中的一列将增加: 这是浏览页面上的HTML和JQUERY <div
如何根据我的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(); } else { $('#numvotes').html(); } } }); }); </script>

这里是它隐藏的PHP页面

<?php require_once($_SERVER['DOCUMET_ROOT'] . '/includes/system/init.php'); // 1. CHECK AD SEE IF THE "$comment_id" IS VALID. I AM GOIG TO RETREIVE THE VALUE OF THE $_POST BEIG SET FROM THE PHP PAGE THAT IS SEDIG 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 //EED TO MAKE THIS ACTUALLY COUT </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 AD JQUERY O 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(); } else { $('#numvotes').html(); } } }); }); </script>

HERE IS THE HIDDE PHP PAGE IT IS SET TO

<?php require_once($_SERVER['DOCUMET_ROOT'] . '/includes/system/init.php'); // 1. CHECK AD SEE IF THE "$comment_id" IS VALID. I AM GOIG TO RETREIVE THE VALUE OF THE $_POST BEIG SET FROM THE PHP PAGE THAT IS SEDIG 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 //EED TO MAKE THIS ACTUALLY COUT </div>

Thanks in advance

最满意答案

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

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/697379.html

相关标签:无
上传时间: 2023-08-27 09:49:29
留言与评论(共有 17 条评论)
本站网友 中国银行副行长
6分钟前 发表
数据库中的一列将增加: 这是浏览页面上的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
本站网友 网上赚钱赚钱
20分钟前 发表
'comment_id=' + comment_id
本站网友 如何瘦小腿
15分钟前 发表
如何根据我的AJAX结果主动增加我的计数器?(How do I actively increment my counter based off of my AJAX results?) 我正在进行我的第一个ajax项目的最后一步
本站网友 农夫山泉标准门事件
25分钟前 发表
data
本站网友 一横线
23分钟前 发表
data
本站网友 伊利潘刚
29分钟前 发表
数据库中的一列将增加: 这是浏览页面上的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
本站网友 云破日出
22分钟前 发表
success
本站网友 天津包子
2分钟前 发表
'comment_id=' + comment_id
本站网友 大概8点20发
5分钟前 发表
success
本站网友 急性脓胸
16分钟前 发表
data
本站网友 记事本文件
10分钟前 发表
当按下这个代码时
本站网友 富矿
9分钟前 发表
success
本站网友 骨头汤
8分钟前 发表
*/ /* 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
本站网友 快乐带回家
22分钟前 发表
'comment_id=' + comment_id
本站网友 气锅鱼
21分钟前 发表
'thumbs.php'
本站网友 烧伤科
21分钟前 发表
'thumbs.php'