Javascript 如何在从服务器接收的表中显示数据

Javascript 如何在从服务器接收的表中显示数据,javascript,php,jquery,html,html-table,Javascript,Php,Jquery,Html,Html Table,我有一个页面index.html(带有表单和表)和一个php文件名indexx.php 当我在index.html中填充数据时,我点击按钮获取数据并请求转到我的文件indexx.php。现在indexx.php从HTML页面获取数据,并使用post方法请求一些视频,我正在成功接收Json数据。但我想在HTML页面中以表格格式显示这些数据 index.html <head> </head> <body> <form action="indexx.p

我有一个页面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>

现在,我想在我的index.html页面中以表格格式显示此文件,您可以使用

json_encode($result,true);

它将使用数据返回关联数组。使用Print\u r打印并在不使用第二个参数的情况下进行检查,您将拥有带键的对象。

首先,不要使用.html文件,而是使用.php:index.php(您当前的index.html文件) 不需要处理php文件(您使用的是indexx.php),因为一切都可以在index.php中完成,下面是一个简单的示例:

<form method='POST'>
    <input type='hidden' name='formSubmitted' value=1>

    <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>
</form>

<!-- form processing STARTS here -->

<?php

if (isset($_POST['formSubmitted'])) {
    print_r($_POST); // you know what to do with this
}

用户ID
类别
获取数据

先生,您可以编辑我的代码并粘贴到这里。因为我是编程新手,只需编写
print\r(json\u encode($result,true))在文件末尾,您将在输出中获得数组。在这里粘贴下一步的结果`就在
indexx.php
中,我尝试了一下,但什么都没有发生,只需打开indexx.php 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"}]}

<form method='POST'>
    <input type='hidden' name='formSubmitted' value=1>

    <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>
</form>

<!-- form processing STARTS here -->

<?php

if (isset($_POST['formSubmitted'])) {
    print_r($_POST); // you know what to do with this
}