您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用Jquery Ajax从Mysql检索数据

使用Jquery Ajax从Mysql检索数据

为了使用Ajax + jQuery检索数据,您应该编写以下代码

 <html>
 <script type="text/javascript" src="jquery-1.3.2.js"> </script>

 <script type="text/javascript">

 $(document).ready(function() {

    $("#display").click(function() {

      $.ajax({    //create an ajax request to display.PHP
        type: "GET",
        url: "display.PHP",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $("#responsecontainer").html(response); 
            //alert(response);
        }

    });
});
});

</script>

<body>
<h3 align="center">Manage Student Details</h3>
<table border="1" align="center">
   <tr>
       <td> <input type="button" id="display" value="Display All Data" /> </td>
   </tr>
</table>
<div id="responsecontainer" align="center">

</div>
</body>
</html>

对于MysqLi连接,请编写以下代码

<?PHP 
$con=MysqLi_connect("localhost","root","");

为了显示数据库中的数据,您应该这样编写:

<?PHP
include("connection.PHP");
MysqLi_select_db("samples",$con);
$result=MysqLi_query("select * from student",$con);

echo "<table border='1' >
<tr>
<td align=center> <b>Roll No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Address</b></td>
<td align=center><b>Stream</b></td></td>
<td align=center><b>Status</b></td>";

while($data = MysqLi_fetch_row($result))
{   
    echo "<tr>";
    echo "<td align=center>$data[0]</td>";
    echo "<td align=center>$data[1]</td>";
    echo "<td align=center>$data[2]</td>";
    echo "<td align=center>$data[3]</td>";
    echo "<td align=center>$data[4]</td>";
    echo "</tr>";
}
echo "</table>";
?>
MySQL 2022/1/1 18:14:23 有493人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶