« jQuery中文入门指南,实例,起点教程 最简单的Javascript表单验证 »

基于JavaScript框架之jquery的ajax实现一例

这个是rate的列子,rate成功返回1,重复rate或者失败返回0.
通过对id=pharsexxx(xxx为投票的短语id)的a对象的css的变化来表示投票结果

  1. var rate_success = '顶好了!';
  2. var rate_failure = '顶过啦!';
  3. function ratephrase(id){
  4. $.ajax({url:"ajax.php",
  5. type:"get",
  6. dataType:"html",
  7. data: "action=vote&id=" + id,
  8. success:function(data){
  9. if (data > 0) {
  10. $("#pharse" + id).css("color", "#000000");
  11. $("#pharse" + id).html(rate_success);
  12. } else {
  13. $("#pharse" + id).css("color", "red");
  14. $("#pharse" + id).html(rate_failure);
  15. }
  16. }
  17. });
  18. }

回复留言

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image

你可以使用XHTML标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>