如果this.className.match Ajax完成

时间:2012-11-29 13:47:34

标签: ajax jquery

我正在尝试确定用户是否点击了确认或拒绝链接。

如果确认......完成时:

idurl = '<?php echo $siteUrl ?>/profile.php?userid='+id+'';
if (idurl == window.location.href) {
     window.location = idurl;
}

否则如果拒绝:

parent.slideUp(300,function() {});
$('.friend-count').load('<?php echo $siteUrl ?>/friendrequestscount.php').fadeIn("fast");

以下脚本在没有:

的情况下运行良好
complete: function() {
        if (this.className.match("confirm")){

如何查看已完成的confirmfriend.php?

<script>
   $('.friendaction').click(function() {
       var id = this.getAttribute('data-userid');
       var requestto = this.getAttribute('data-requestto'),
       parent = $(this).closest("li"),
           url = this.className.match("confirm") 
              ? "confirmfriend.php" 
              : "removefriend.php", 
           liReference = $(this).parent();
       $.ajax(url + "?userid=" + id, {
           complete: function() {
            if (this.className.match("confirm")){
                      idurl = '<?php echo $siteUrl ?>/profile.php?userid='+id+'';
                      if (idurl == window.location.href) {
                          window.location = idurl;
                      }
            } else {
                    parent.slideUp(300,function() {});
                    $('.friend-count').load('<?php echo $siteUrl ?>/friendrequestscount.php').fadeIn("fast");
            }
           }
       });
   });
</script>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

<script>
   $('.friendaction').click(function() {
       var id = this.getAttribute('data-userid');
       var requestto = this.getAttribute('data-requestto'),
       parent = $(this).closest("li"),
           url = this.className.match("confirm") 
              ? "confirmfriend.php" 
              : "removefriend.php", 
           liReference = $(this).parent();
       $.ajax(url + "?userid=" + id, {
           complete: function() {
            if (url == "confirmfriend.php"){
                      idurl = '<?php echo $siteUrl ?>/profile.php?userid='+id+'';
                      if (idurl == window.location.href) {
                          window.location = idurl;
                      }
            } else {
                    parent.slideUp(300,function() {});
                    $('.friend-count').load('<?php echo $siteUrl ?>/friendrequestscount.php').fadeIn("fast");
            }
           }
       });
   });
</script>