2011-07-05 45 views
-1

我有以下的jQuery Ajax请求后jQuery的Ajax请求的问题

$(document).ready(function(){ 
       var friendrequest = $(".friendrequest").val(); 
       $(".afriendreq").click(function(){ 
        $(".afriendreq").hide(); 
        $.ajax({ type: "POST", url:"functions/ajaxfriends.php", data:"friendrequest" ,success:function(result){ 
          $(".cfriendreq").show(); 
         }}); 
       }); 
      }); 

它从这里

 while ($row = mysql_fetch_array($search)) { 
         d 
         ?> 
         <div id="search_container"> 
          <div id="search_image"><img src="<?php echo $row['picture'] ?>"></img></div> 
          <input type="hidden" value="<?php echo $row['id'] ?>" id="friendrequest" ></input> 
          <div id="search_name"><a href="profile.php?id=<?php echo $row['bigid'] ?>.'"> <?php echo $row['first_name'] . " " . $row['last_name']; ?></a> </div> 
          <div id="search_friend"><a class="afriendreq">Send Friend Request</a><a class="cfriendreq" style="display:none;">Cancel Friend Request</div> 
         </div><?php 
        echo "<br />"; 
       } 
        ?> 

获取输入遗憾的是它不工作,虽然。任何人都可以找到问题,因为它是在窃听我? 同样的功能/ ajaxfriends.php是

<?php 
include 'functions.php'; 
if (isset($_POST['friendrequest'])){ 
$friendrequest= $_POST['friendrequest']; 
$friendrequest= filter ($_POST['friendrequest']); 
$sql_connectfriend = " INSERT INTO friends (`useridone` ,`useridtwo` ,`request`) VALUES ('$_SESSION[user_id]', '$friendrequest', '1' "; 
$search = mysql_query($sql_connectfriend, $link) or die("Insertion Failed:" . mysql_error()); 
} 
?> 

任何人都可以看到,为什么? 在此先感谢。

+0

数据: “friendrequest”?这将通过什么形式?您应该序列化表单值或构建一个字符串url并将其用于数据。 –

+0

这将仅仅通过这个$ row ['id']从这里 ”id =“friendrequest”> – viper

回答

2

尝试:

$.ajax({ 
    url: 'functions/ajaxfriends.php', 
    type: 'POST', 
    data: { friendrequest: friendrequest }, 
    success: function(result) { 
     $('.cfriendreq').show(); 
    } 
}); 
+0

nop不幸的是它没有工作:( 我想也许这是因为它在$(“。afriendreq”)元素内,但它没有任何意义。 – viper

+0

@Simos Mikelatos,如果'.afriendreq'是一个链接可能需要通过从'.click'处理程序返回false来取消默认操作,或者AJAX请求可能没有时间执行。 –