【发布时间】:2015-02-10 21:59:48
【问题描述】:
我目前正在学习 ajax 和 php。我想要做的是从 php 文件中回显表行。这是我的代码。
HTML 代码:
<table class = "table table-hover table-striped">
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Price</th>
<th>Terms</th>
</tr>
<-- I want the new table row to appear here -->
</table>
PHP 代码
<?php
$x = 10;
while($x > 0)
{
echo '<tr>
<td>'.$x.'</td>
<td>'.$x.' Name</td>
<td>'.$x.' Pesos</td>
<td>'.$x.' Years</td>
</tr>';
$x--;
}
?>
Ajax 脚本
<script>
function showDetails()
{
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");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myNewTableRow").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","sample-php-ajax.php",true);
xmlhttp.send();
}
</script>
在哪里放置 ID 以便在我使用 ajax 调用 php 文件时显示它想要回显的内容?
【问题讨论】:
-
你的 ajax 代码在哪里?
-
我在这里没有看到任何关于 ajax 的代码。
-
我很抱歉没有为 ajax 添加脚本。我已经对其进行了编辑,感谢您抽出宝贵时间阅读。