当我使用header("Content-Type: application/json; charset=UTF-8");
当我在文件中使用波纹表代码时,它在浏览器上显示相同的代码,它应该只显示内部内容。在浏览器表上显示如下。
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Email</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
应该显示
Name1 Name2 Name3
这是我的完整代码
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("localhost", "root", "", "angular");
$result = $conn->query("SELECT * FROM user");
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") { $outp .= ","; }
$outp .= '{"id":"' . $rs["id"] . '",';
$outp .= '"name":"' . $rs["name"] . '",';
$outp .= '"father":"'. $rs["father"] . '"}';
$outp .= '"designation":"'. $rs["designation"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo($outp);
?>
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Email</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>