<bdo id='WmBbX'></bdo><ul id='WmBbX'></ul>
    <tfoot id='WmBbX'></tfoot>
  1. <legend id='WmBbX'><style id='WmBbX'><dir id='WmBbX'><q id='WmBbX'></q></dir></style></legend>

    <small id='WmBbX'></small><noframes id='WmBbX'>

  2. <i id='WmBbX'><tr id='WmBbX'><dt id='WmBbX'><q id='WmBbX'><span id='WmBbX'><b id='WmBbX'><form id='WmBbX'><ins id='WmBbX'></ins><ul id='WmBbX'></ul><sub id='WmBbX'></sub></form><legend id='WmBbX'></legend><bdo id='WmBbX'><pre id='WmBbX'><center id='WmBbX'></center></pre></bdo></b><th id='WmBbX'></th></span></q></dt></tr></i><div id='WmBbX'><tfoot id='WmBbX'></tfoot><dl id='WmBbX'><fieldset id='WmBbX'></fieldset></dl></div>

      实时 jQuery Ajax PHP 中的 UP 或 DOWN 投票

      UP or DOWN Voting in Real-Time jQuery Ajax PHP(实时 jQuery Ajax PHP 中的 UP 或 DOWN 投票)

        <bdo id='MXuNS'></bdo><ul id='MXuNS'></ul>

              <tfoot id='MXuNS'></tfoot>

              <i id='MXuNS'><tr id='MXuNS'><dt id='MXuNS'><q id='MXuNS'><span id='MXuNS'><b id='MXuNS'><form id='MXuNS'><ins id='MXuNS'></ins><ul id='MXuNS'></ul><sub id='MXuNS'></sub></form><legend id='MXuNS'></legend><bdo id='MXuNS'><pre id='MXuNS'><center id='MXuNS'></center></pre></bdo></b><th id='MXuNS'></th></span></q></dt></tr></i><div id='MXuNS'><tfoot id='MXuNS'></tfoot><dl id='MXuNS'><fieldset id='MXuNS'></fieldset></dl></div>
                <tbody id='MXuNS'></tbody>
                <legend id='MXuNS'><style id='MXuNS'><dir id='MXuNS'><q id='MXuNS'></q></dir></style></legend>
              1. <small id='MXuNS'></small><noframes id='MXuNS'>

              2. 本文介绍了实时 jQuery Ajax PHP 中的 UP 或 DOWN 投票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                好的,下面是我正在做的事情的简要说明:我有一个网站,人们可以在其中投票支持或反对冠军".这些冠军从 100 点生命值开始.如果你对一个特定的英雄进行 UP 投票,他们的生命值现在是 101.DOWN 投票是 99.

                Alright, here's a quick explanation of what I am doing: I have a website where people can vote UP or DOWN to a "champion." These champions start with 100 health. If you were to UP vote a specific champion, their health would now be 101. DOWN voting it would be 99.

                这个网站已经启动并运行了 5 个赛季(有超过 1200 名成员在玩).所以有很多投票同时进行.现在一切正常.但是,在下个赛季,我将实现 jquery/ajax 以进行实时"投票(因此页面不需要在您每次投票时刷新).

                This site is up and running and has been for 5 seasons now (there's over 1200 members that play). So there's a lot of voting going on at once. It all works fine now. BUT, for this next season, I will be implementing jquery/ajax for "real-time" voting (so the page doesn't need to refresh every time you vote).

                我现在遇到的困难是,首先,我对 ajax/js 并不擅长.但是,主要问题是当有人点击投票时,我需要一种方法来从数据库中获取实时数据,然后将其放入 jquery/ajax 查询中,然后实时输出真实数据(或至少我觉得这是应该做的).

                The struggle I am having right now with this is, first off, I am not great with ajax/js. However, the main issue is when someone clicks a vote, I need a way to grab the LIVE data from the DB and then throw that into the jquery/ajax query and then output the real data, in real-time (or at least I feel this is what should be done).

                还有第二部分……人们每小时可以投票 3 次.页面顶部有一条通知,显示他们还剩多少票,您还有 3 个操作."这又是一次,按原样工作正常,但我想还需要使用 ajax 进行修复才能实现实时性.

                There is also a second part to this...people are allowed to vote 3x per hour. There is a notification at the top of the page showing them how many votes they have left, "You have 3 actions remaining." This is again, working fine as is, but I imagine would need to be fixed in with the ajax to be real-time as well.

                我希望我解释得足够好.如果没有,请告诉我!任何帮助将不胜感激!

                I hope I explained this well enough. If not, please let me know! Any help would be greatly appreciated!

                代码:

                $("a.vote-heal").click(function(){
                    var votes;
                    var champ;
                    var health;
                    champ = $(this).attr('id');
                
                    votes = $("#votesLeft").text();
                    votes--;
                
                    //the main ajax request
                    $.getJSON("/load-champ.php?champ="+champ, function(data) {
                        $.each(data, function(i,data) {
                            health = data.health;
                            health++;
                        });
                        $.ajax({
                            type: "POST",
                            url: "/votes.php",
                            data: "champ="+champ+"&action=heal",
                            success: function(msg) {
                                $('#'+champ+' .health-inner').html(health);
                                $('#header .vote-remain').html('You have <strong><span id="votesLeft">'+votes+'</span> Actions</strong> remaining');
                                $('#'+champ+' .voting').html('<a id='+champ+'" class="button vote-hurt" href="javascript:;">Hurt '+champ+'</a><div class="button vote-heal action-tooltip">Heal '+champ+'</div>');
                            }
                        });
                    });
                });
                

                推荐答案

                所有这些都只是使用 JSON 返回的数据库查询.也许在后端有两个操作 - 投票和刷新.

                All of this is just database queries that are returned with JSON. Maybe have two actions on the backend - vote and refresh.

                在投票方法中,首先查看投票者当前的计数.如果还有票数,让冠军的分数上升或下降.

                In the vote method, first check to see the voter's current count. If there are votes left, have the champion's score go up or down.

                然后,返回这个数组:

                1. 列表项
                2. 冠军投票
                3. 剩下的票
                4. 错误(如果存在)

                在刷新方法中(每 x 秒或分钟轮询一次后端服务器)返回当前投票数.

                In the refresh method (which would poll the backend server every x number of seconds or minutes) return the number of current votes.

                一个相当简单的ajax实现.

                A fairly easy implementation of ajax.

                希望这有帮助!

                AJAX 学习链接

                使用 jQuery,它超级、超级简单.方法如下:

                With jQuery, it is super, super easy. Here's how:

                • http://api.jquery.com/jQuery.parseJSON/
                • http://api.jquery.com/jQuery.getJSON/
                • http://php.net/manual/en/function.json-编码.php
                • 官网:http://www.json.org/
                • http://www.hunlock.com/blogs/Mastering_JSON_(_JavaScript_Object_Notation_)

                这篇关于实时 jQuery Ajax PHP 中的 UP 或 DOWN 投票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <tbody id='cUZud'></tbody>

                  <i id='cUZud'><tr id='cUZud'><dt id='cUZud'><q id='cUZud'><span id='cUZud'><b id='cUZud'><form id='cUZud'><ins id='cUZud'></ins><ul id='cUZud'></ul><sub id='cUZud'></sub></form><legend id='cUZud'></legend><bdo id='cUZud'><pre id='cUZud'><center id='cUZud'></center></pre></bdo></b><th id='cUZud'></th></span></q></dt></tr></i><div id='cUZud'><tfoot id='cUZud'></tfoot><dl id='cUZud'><fieldset id='cUZud'></fieldset></dl></div>
                  1. <small id='cUZud'></small><noframes id='cUZud'>

                      <legend id='cUZud'><style id='cUZud'><dir id='cUZud'><q id='cUZud'></q></dir></style></legend>

                      <tfoot id='cUZud'></tfoot>
                      • <bdo id='cUZud'></bdo><ul id='cUZud'></ul>