JQuery:拇指向上和向下评级系统?

Pra*_*ant 4 javascript ajax jquery rating

我想使用jquery在我的网络应用程序中实现拇指向上和向下评级系统.请告诉我一些插件或代码如何在我的网站上实现拇指向上和向下评级系统,请分享链接或资源.

谢谢

Sam*_*son 13

jQuery的

这只是一个翻转效果,以及等待更新数据库条目的地址.这不是真正的jQuery.这种"肉"将是您的数据库和服务器端脚本.

$("a.voteup").click(function(){
  $.get("updatescore.php", {"id":"112","score":"1"}, function(response){
    /* Do something with the response */
  });
});
Run Code Online (Sandbox Code Playgroud)

该代码可能有点偏,但它足够接近传达这一点.从那里,您将有一个服务器端脚本等待接收:

PHP/MySQL

重要提示:请勿使用原样.仅用于演示.
ASP.NET:我从你过去的问题中注意到你可能在.NET技术中工作.这里完成的过程仍然会非常相似.您将处理传入的请求,要求用户登录,他们的分数为1或-1,以及您希望的任何其他内容.

  session_start();
  $userid = $_SESSION["userid"];

  $vote = $_GET["score"]; /* Limit to 1 or -1 */
  $article = $_GET["id"];

  /* Whatever is printed here will be the 'response' variable
     over in our jQuery callback function. Ideally, this function
     would only allow the vote if the following are true:
       1. User has not yet voted on this article
       2. Score is 1 or -1
       3. Voting is enabled on this article
       4. User is indeed logged in */
  print castVote($article, $vote, $userid);

?>
Run Code Online (Sandbox Code Playgroud)

  • Daok,我的代码不用于制作.当然这不安全.它意味着传达一个想法,而不是一个完整的解决方案. (3认同)
  • 与所有事情一样,服务器端验证也是必须的.请注意,他*确实*说"不要原样使用". (3认同)

Pat*_*ins 7

这是一个使用JQuery与PHP/MySQL中的后端竖起大拇指的样式.

链接到代码(您可以在线尝试演示,所有源代码都在那里)