开发者

Jquery post ajax request problem

开发者 https://www.devze.com 2023-03-17 06:43 出处:网络
I have the following jquery ajax request $(document).ready(function(){ var friendrequest =$(\".friendrequest\").val();

I have the following jquery ajax request

$(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();
                        }});
                });
            });

And it gets the input from here

       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 />";
                }
                    ?>

Unfortunately it's not working though. Can anyone find the problem because it's bugging me? Also the functions/ajaxfriends.php is

<?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());
}
?>

Can anyone see why? Thanks in advance.


Try:

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

精彩评论

暂无评论...
验证码 换一张
取 消