【发布时间】:2018-10-28 02:11:31
【问题描述】:
您好,我是 javascript/JS 或 jquery 的新手。我只知道用 php 编写代码,但我也想学习 JS。 我的代码没有显示从 json_encode 到 HTML TABLE 的获取数据。 请帮我这样做。我一直在搜索如何做到这一点。但他们总是像 var 一样使用,但是当我尝试做同样的事情时,我没有显示任何内容,所以我从基础重新开始。
我想要的是将从 process.php json_encode 获取的数据显示到我的 html 表中仅 TBODY 部分而不是整个表。
如有遗漏请指正。(即jquery插件?请在哪里下载)
下面是我的代码。
对于 Index.html
<html>
<head>
<title>LEARN AJAX</title>
<style type="text/css">
#mytable,td{
border:0px solid blue;
}
</style>
</head>
<body>
<table>
<thead>
<th>ID No.</th>
<th>Full Name</th>
<th>Address</th>
</thead>
<tbody>
<!--*/data should go Here-- >
<!--Data from process.php-->
</tbody>
</table>
</body>
</html
对于 Process.php
<?php
include ('connection.php');
if (mysqli_connect_errno()) {
die('Could not connect: ' . mysql_error());
}
$return_arr = array();
$sql="SELECT * FROM members";
if ($result = mysqli_query( $conn, $sql )){
while ($row = mysqli_fetch_array($result))
{
$row_array['id'] = $row['id'];
$row_array['name'] = $row['fname'];
$row_array['address'] = $row['ad'];
array_push($return_arr,$row_array);
}
}
//echo json_encode($return_arr);
$result = json_encode($return_arr);
?>
对于我的数据库连接:
<?php
//for MySQLi OOP
$conn = new mysqli('localhost', 'root', '', 'mydatabase');
if($conn->connect_error){
die("Connection failed: " . $conn->connect_error);
}
?>
【问题讨论】:
-
请添加您的代码
-
嗨,我添加了代码。请帮帮我。
标签: javascript jquery html arrays json