我是 web 开发的新手,我真的需要一些帮助。我想使用 ajax 显示一个 html 表。此代码来自两个不同的文件。我这样做对吗?
这是我的 index.html
<html>
<body>
<script>
function loadXMLDoc()
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","table.php",true);
xmlhttp.send();
}
</script>
<form action = "insert.php" method="post">
Firstname: <input type="text" name="firstname"></br>
Lastname: <input type="text" name="lastname"></br>
Middlename: <input type="text" name="middlename"></br>
<input type="submit" onclick="loadXMLDoc()">
</form>
<div id="myDiv"></div>
</body>
</html>
这是我的table.php。当我单击提交按钮时,没有任何反应。有没有人可以告诉我我这样做是否正确?
<html>
<body>
<table border = 1>
<tr>
<th>FIRSTNAME</th>
<th>LASTNAME</th>
<th>MIDDLENAME</th>
<th>DELETE</th>
</tr>
/* <?php
$con = mysqli_connect("localhost","root","","study");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to mysql" . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM sample_employers");
while($row=mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['middlename'] . "</td>";
echo "<td> <input type='button' value='Delete' </td>";
echo "</tr>";
}
mysqli_close($con);
?>
</table>
</body>
</html>