Bootstrap表显示JSON数据 [英] Bootstrap table showing JSON data

查看:659
本文介绍了Bootstrap表显示JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上运行Bootstrap,并结合了一个名为 Bootstrap的bootstrap插件表的。
它要求将数据作为JSON文件传送。

I'm running Bootstrap on my site, combined with a bootstrap plugin called Bootstrap Tables. It requests the data to be delivered as a JSON file.

我遇到麻烦但要让它工作。我一直在努力一整天,但没有结果。我还尝试了谷歌和其他代码示例。

I'm having trouble however getting it to work. I've been trying for a full day now, but to no result. I also tried Google and other code examples.

我的JSON文件看起来像

My JSON file looks like

    {"giveawayid":"101", "creatorid":"7962290569"} 

我的测试页面如下所示:

My test page looks like:

<html lang="en"> 
<head>
    <!-- Latest compiled and minified JavaScript -->
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-table.js"></script>
    <!-- Bootstrap - Latest compiled and minified CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-table.css">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Test</title>
</head>

<body>
<p>&nbsp;</p>
<div class="container">

    <!-- table -->
    <table class='table' data-toggle="table" data-url="test.json">
    <thead>
    <TR>
        <TH data-field="giveawayid" data-align="center" data-sortable="true">giveawayid</TH>
        <TH data-field="creatorid" data-align="center" data-sortable="true">creatorid</TH>
    </TR>
    </thead>
    </table>

</div>
</body></html>

现在您可以通过可排序的标题看到,Bootstrap Table javascript处于活动状态。

Now as you can see by the sortable headers, the Bootstrap Table javascript is active.

我还检查了JSON文件,虽然我自己制作了它们,但它们似乎都有效。
但是系统似乎没有处理数据。我怎么能确定他们的json文件是否正确?我查看了开发人员工具并没有看到错误。

I also checked the JSON files and although I made them myself, they seem valid. However the system doesn't seem to handle the data. How can I be sure they json files are correct? I checked with developer tools and didn't see an error.

有没有人知道会出现什么问题?

Does anyone have any idea what could be going wrong?

编辑:以下解决方案

推荐答案

解决方案:

我的.json文件不是正确的数组。
使用以下代码生成一个可用的JSON文件:

My .json files weren't proper array's. Use the following code to make a working JSON file:

<?php
header('Content-type: application/json');
// Connect to the MySQL database
require_once ("lib/connect.php");

// query - description of query
$sql = "SELECT column FROM table";
    $result = mysqli_query($dbConnection, $sql);

if ($result->num_rows > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $json[]=$row;
    }
}

// CLOSE CONNECTION
mysqli_close($dbConnection);

echo json_encode($json);
?>

这篇关于Bootstrap表显示JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆