Jquery发布了ajax请求问题

时间:2011-07-05 21:07:56

标签: html ajax jquery

我有以下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());
}
?>

谁能明白为什么? 提前谢谢。

1 个答案:

答案 0 :(得分:2)

尝试:

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