【问题标题】:PHP AJAX button click counterPHP AJAX 按钮点击计数器
【发布时间】:2017-07-28 15:29:05
【问题描述】:

我想制作一个按钮点击计数器。当您单击按钮时,其中的文本会发生变化,当单击按钮时,我想写入数据库,但我无法管理。

<button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;"><h4><i class="glyphicon glyphicon-earphone" aria-hidden="true">  </i> XXXX XXX XXX <h6>Show Number</h6></h4></button>

document.getElementById("textChanger").onclick= function(){
        document.getElementById("textChanger").innerHTML="<h4><i class=\"glyphicon glyphicon-earphone\" aria-hidden=\"true\">  </i> <?php echo $nrTelefonAnunt ?> </h4>";
         }

这是我管理文本更改的代码,现在我可以做些什么来写入数据库,我尝试了一些方法但没有奏效

【问题讨论】:

  • 假设数据库不在您的本地计算机上,您需要进行远程调用,以便执行一些服务器端脚本。

标签: php jquery sql ajax database


【解决方案1】:

感谢大家通过添加以下内容得到的答案:

$('#textChanger').click(function(){
    $.ajax({
        url : 'rate.php?idanunt="<?php echo $idAnunt ?>"', 
        type : 'post',  
        success : function(data){
        }
    });
});

【讨论】:

    【解决方案2】:

    试试这个

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;">1</button>
    <script>
    document.getElementById("textChanger").onclick= function(){
            var count = document.getElementById("textChanger").innerHTML;
            count = parseInt(count) + 1;
            document.getElementById("textChanger").innerHTML=count;
             }
    </script>

    【讨论】:

      【解决方案3】:

      试试这个

       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
       <button type="button" class="btn btn-info" style="width:90%;" id="textChanger" onclick="counter;"><h4><i class="glyphicon glyphicon-earphone" aria-hidden="true">  </i> <span>XXXXX</span> <h6>Show Number</h6></h4></button>
      
      <script>
      count=0;
       $(document).on("click","button",function(){
           count++;
           $('span').text(count);
      
      
      
        });  
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-06
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        相关资源
        最近更新 更多