我想知道如何从已经设置的数据库中提取表格。我有自己的代码,但它无法解决。目标是让人们点击一个按钮,该按钮运行运行PHP文件的JavaScript函数,然后在我拥有的特定div中将其显示在网站上。如果有人能帮助我弄清楚什么是错的那将是非常棒的!这是代码:
Kataajax.js
tkakata(){
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlHttp = new XMLHttpRequest();
}
else {
// code for IE6, IE5
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(!xmlHttp)
alert("Something went wrong")
else
return xmlHttp
}
function process(){
if(xmlHttp.readyState==0 || xmlHttp.readyState==4)
{
xmlHttp.open("GET", "tkakatagrab.php", true)
xmlHttp.onreadystatechange = handleServerResponse();
xmlHttp.send(null);
}
else
{
setTimeout('process()',1000);
}
}
function handleServerResponse()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data;
document.getElementById("displayrank").innerHTML = message;
setTimeout('process()',1000);
}
else
{
alert("Database not connecting!")
}
}
}
}
tkakatagrab.php
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';
$con = mysqli_connect('IP','username','password','TKACONT');
if(!$con){
die('Could not connect: ' . mysqli_error($con));
}
$sql="SELECT Firstname,Lastname,Kata FROM Contestant ORDER BY Kata DESC";
$result = mysqli_query($con,$sql);
echo '<response>';
echo "<table>
<tr>
<th>Points</th>
<th>Firstname</th>
<th>Lastname</th>";
//while loop right here
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Kata'] . "</td>";
echo "<td>" . $row['Firstname'] . "</td>";
echo "<td>" . $row['Lastname'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo '</response>';
mysqli_close($con);
?>