【发布时间】:2020-02-27 23:44:35
【问题描述】:
我有一个页面 index.html(带有表格和表格)和一个 php 文件名 indexx.php 当我在 index.html 中填写数据时,我单击按钮获取数据并请求转到我的文件 indexx.php。现在 indexx.php 从 HTML 页面获取数据并使用 post 方法请求一些视频,我成功接收 Json 数据。但我想以表格格式在我的 HTML 页面中显示这些数据。
index.html
<head>
</head>
<body>
<form action="indexx.php" method="POST" >
<div class="container" style="width:100%;">
<center></center>
</div>
<div class="container" style="width:100%;">
<label for="userId"><b>UserId</b></label>
<input type="number" placeholder="Enter Your User Id" name="userId" autofocus required>
<label for="categoryId"><b>categoryId</b></label>
<input type="number" placeholder="Enter categoryId" name="categoryId" required>
<button type="submit" >GET DATA</button>
</div>
</form>
<div class="wrapper">
<div class="profile">
<table id= "userdata" width="50%" border="2">
<thead>
<th>VIDEO NAME</th>
<th>DATE</th>
<th>TIME</th>
<th>DURACTION</th>
<th>LIVE STATUS</th>
<th>LINK</th>
</thead>
<tbody>
<!-- here you will loop through the data you have received from curl and fill it in the tbody, and this entrie thing will be done when the page loads -->
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
</body>
</html>
我的 indexx.php
<?php
$userId = $_POST['userId'];
$categoryId = $_POST['categoryId'];
$url = 'https://www.serversample.php';
$data = array('userId' => $userId, 'categoryId' => $categoryId);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
print($result);
?>
我从另一台服务器收到的 JSON 文件示例
{"yourvideo":[{"Id":"55","videoName":"CLASS-3","date":"2 AUG 2015","time":"9:58 PM","video":"sCLKbhghghhgb","image":"https://img.youtube.com/vi/sjjZB4jjuhwc/0.jpg","videoType":"video","videoDuration":"02:08:88","liveStatus":"offline","testId":"0"},{"Id":"6985","videoName":"CLASS-4","date":"29 AUG 2018","time":"8:52 PM","video":"gtghnhyv","image":"https://img.youtube.com/vi/uygbnhjhg/0.jpg","videoType":"video","videoDuration":"02:81:18","liveStatus":"offline","testId":"0"}]}
现在我想在我的 index.html 页面中以表格格式显示这个文件
【问题讨论】:
标签: javascript php jquery html html-table