使用Jquery Ajax从Mysql中检索数据
list.php
:一个简单的ajax代码,我只想显示Mysql表的记录:
<html><head> <script src="jquery-1.9.1.min.js"> </script> <script> $(document).ready(function() { var response = ''; $.ajax({ type: "GET", url: "Records.php", async: false, success: function(text) { response = text; } }); alert(response); }); </script></head><body> <div id="div1"> <h2>Let jQuery AJAX Change This Text</h2> </div> <button>Get Records</button></body></html>
Records.php是从Mysql获取记录的文件。
在数据库中只有两个字段:“名称”,“地址”。
<?php //database name = "simple_ajax" //table name = "users" $con = mysql_connect("localhost","root",""); $dbs = mysql_select_db("simple_ajax",$con); $result= mysql_query("select * from users"); $array = mysql_fetch_row($result);?><tr> <td>Name: </td> <td>Address: </td></tr><?php while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>$row[1]</td>"; echo "<td>$row[2]</td>"; echo "</tr>"; } ?>
此代码无效。
aluckdog