加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

投票喜欢/不喜欢 ajax无刷新

发布时间:2020-12-16 00:36:09 所属栏目:百科 来源:网络整理
导读:投票喜欢/不喜欢 ajax无刷新 演示 JavaScript Code scripttype= "text/javascript" $(document).ready( function () { $( ".like" ).click( function () var id=$( this ).attr( "id" ); var name=$( this ).attr( "name" ); var dataString= 'id=' +id+ 'na

投票喜欢/不喜欢 ajax无刷新

演示

JavaScript Code
  1. <scripttype="text/javascript">
  2. $(document).ready(function()
  3. {
  4. $(".like").click(function()
  5. varid=$(this).attr("id");
  6. varname=$(this).attr("name");
  7. vardataString='id='+id+'&name='+name;
  8. $("#votebox").slideDown("slow");
  9. $("#flash").fadeIn("slow");
  10. $.ajax
  11. ({
  12. type:"POST",
  13. url:"rating.php",
  14. data:dataString,
  15. cache:false,0);">success:function(html)
  16. {
  17. $("#flash").fadeOut("slow");
  18. $("#content").html(html);
  19. }
  20. });
  21. });
  22. $(".close").click(function()
  23. $("#votebox").slideUp("slow");
  24. </script>

XML/HTML Code

    <divstyle="margin:50px">
  1. ahref="#"class="like"id="1"name="up">喜欢</a>--<ahref="#"class="like"id="1"name="down">不喜欢</a>
  2. divid="votebox">
  3. spanid='close'><ahref="#"class="close"title="CloseThis">X</a></span>
  4. divstyle="height:13px">
  5. divid="flash">Loading........</div>
  6. </div>
  7. divid="content">
  8. div>

rating.php

PHP Code
    <?php
  1. include("conn.php");
  2. if($_POST['id'])
  3. $id=mysql_escape_String($_POST['id']);
  4. $name=mysql_escape_String($_POST['name']);
  5. mysql_query("updatemessagesset$name=$name+1whereid='$id'");
  6. $result=mysql_query("selectup,downfrommessageswhereid='$id'");
  7. $row=mysql_fetch_array($result);
  8. $up_value=$row['up'];
  9. $down_value=$row['down'];
  10. $total=$up_value+$down_value;
  11. $up_per=($up_value*100)/$total;
  12. $down_per=($down_value*100)/$total;
  13. ?>
  14. <divstyle="margin-bottom:10px">
  15. <b>Ratingsforthisarticle</b>(<?phpecho$total;?>total)
  16. </div>
  17. <tablewidth="700px">
  18. <tr>
  19. <tdwidth="30px"></td>
  20. <tdwidth="60px"><?phpecho$up_value;?></td>
  21. <tdwidth="600px"><divid="greebar"style="width:<?phpecho$up_per;?>%"></div></td>
  22. </tr>
  23. $down_value;?></td>
  24. <tdwidth="600px"><divid="redbar"style="width:<?phpecho$down_per;?>%"></div></td>
  25. </table>
  26. <?php
  27. }
  28. ?>


原文地址: http://www.freejs.net/article_jquerywenzi_143.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读