使用jQueryAjax将数据发送到php并检索响应

使用jQueryAjax将数据发送到php并检索响应,php,jquery,mysql,ajax,mysqli,Php,Jquery,Mysql,Ajax,Mysqli,我正在尝试这样做: 当用户单击包含mysqli行的briefinfo div时,将student id发送到id.php,然后php文件将根据student id获取所有数据并将其回显,这样我就可以使用ajax将其放入原始index.php中 <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script> &

我正在尝试这样做: 当用户单击包含mysqli行的briefinfo div时,将student id发送到id.php,然后php文件将根据student id获取所有数据并将其回显,这样我就可以使用ajax将其放入原始index.php中

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>    
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    //in your Javascript, put
    $(document).ready ( function () {
    $("#briefinfo").click (function(){
    $.ajax({  
        type: 'POST',  
        url: 'id.php', 
        var studentid = "<?php echo $studentid; ?>";
        data: { id: studentid },
        success: function(response) {
                $("#briefinfo").html(response);
            }
    });
    });
    });
        </script>

//在Javascript中,输入
$(文档).ready(函数(){
$(“#简要信息”)。单击(函数(){
$.ajax({
键入:“POST”,
url:'id.php',
var studentid=“”;
数据:{id:studentid},
成功:功能(响应){
$(“#简要信息”).html(回复);
}
});
});
});
请帮忙。 这是id.php

<?php

    // connect to the database
    include('connect-db.php');
    // confirm that the 'id' variable has been set
    require_once("db.php");
        $id = $_POST['id'];
        if ($result = $mysqli->query("SELECT * FROM requests WHERE student_id=$id"))
        {
                if ($result->num_rows > 0)
                {
                    echo "<table border='1' cellpadding='10'>";
                    echo "<tr><th>Document #</th><th>Student #</th>
                    <th>Documents needed</th><th>Edit</th><th>Delete</th>
                    <th>recorded comment</th><th>unverify</th><th>comment</th><th>payment amount</th><th>set payment</th>
                    </tr>";


                        while ($row = $result->fetch_object())
                        {
                            echo "<tr>";
                            echo "<td>" . $row->id . "</td>";
                            $studentid=$row->student_id;
                            echo "<td><a href='id.php?id=" . $row->student_id . "'>$studentid</a></td>";
                            echo "<td>" . $row->document . "</td>";
                            echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>";
                            echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>";
                            echo "<td>" . $row->comment . "</td>";
                            echo "<td><a href='unverify.php?id=" . $row->id . "'>unverify</a></td>";
                            echo "<td><a href='comments.php?id=" . $row->id . "'>comment</a></td>";
                            echo "<td>" . $row->paymentamount . " pesos";"</td>";
                            echo "<td><a href='paymentamount.php?id=" . $row->id . "'>set amount</a></td>";
                            echo "</tr>";
                        }
                        echo"<br><br>";
                        echo "</table>";
                }
                else
                {
                    echo "No results to display!";
                }
        }
        else
        {
                echo "Error: " . $mysqli->error;
        }

    ?>

实际上。。。var在ajax中,只需将其作为值添加到数据中即可

    $.ajax({
    type: 'POST',
    url: 'id.php',
    data: {
        id: "<?php echo $studentid; ?>"
    },
    success: function(response) {
        $("#briefinfo").html(response);
    }
});
$.ajax({
键入:“POST”,
url:'id.php',
数据:{
id:“
},
成功:功能(响应){
$(“#简要信息”).html(回复);
}
});

与“内容”相关的是什么?通常这类似于jQuery('yourdiv').html(response);这基本上是一个侧面的东西。因此在#briefinfo中,它有来自mysql的学生id、姓名等。我希望它在单击时显示更多数据(mysql表中的每一行)。我只是猜测,因为您没有显示希望添加ajax响应的实际HTML。我改了,但还是不起作用。我不知道它为什么不起作用。请看我对答案的补充。