投票喜欢/不喜欢 ajax无刷新
演示
JavaScript Code
- <scripttype="text/javascript">
- $(document).ready(function()
- {
- $(".like").click(function()
- varid=$(this).attr("id");
- varname=$(this).attr("name");
- vardataString='id='+id+'&name='+name;
- $("#votebox").slideDown("slow");
- $("#flash").fadeIn("slow");
- $.ajax
- ({
- type:"POST",
- url:"rating.php",
- data:dataString,
- cache:false,0);">success:function(html)
- {
- $("#flash").fadeOut("slow");
- $("#content").html(html);
- }
- });
- });
- $(".close").click(function()
- $("#votebox").slideUp("slow");
- </script>
XML/HTML Code
<divstyle="margin:50px">
- ahref="#"class="like"id="1"name="up">喜欢</a>--<ahref="#"class="like"id="1"name="down">不喜欢</a>
- divid="votebox">
- spanid='close'><ahref="#"class="close"title="CloseThis">X</a></span>
- divstyle="height:13px">
- divid="flash">Loading........</div>
- </div>
- divid="content">
- div>
rating.php
PHP Code
<?php
- include("conn.php");
- if($_POST['id'])
- $id=mysql_escape_String($_POST['id']);
- $name=mysql_escape_String($_POST['name']);
- mysql_query("updatemessagesset$name=$name+1whereid='$id'");
- $result=mysql_query("selectup,downfrommessageswhereid='$id'");
- $row=mysql_fetch_array($result);
- $up_value=$row['up'];
- $down_value=$row['down'];
- $total=$up_value+$down_value;
- $up_per=($up_value*100)/$total;
- $down_per=($down_value*100)/$total;
- ?>
- <divstyle="margin-bottom:10px">
- <b>Ratingsforthisarticle</b>(<?phpecho$total;?>total)
- </div>
- <tablewidth="700px">
- <tr>
- <tdwidth="30px"></td>
- <tdwidth="60px"><?phpecho$up_value;?></td>
- <tdwidth="600px"><divid="greebar"style="width:<?phpecho$up_per;?>%"></div></td>
- </tr>
- $down_value;?></td>
- <tdwidth="600px"><divid="redbar"style="width:<?phpecho$down_per;?>%"></div></td>
- </table>
- <?php
- }
- ?>
原文地址:
http://www.freejs.net/article_jquerywenzi_143.html (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|