【问题标题】:How should i be including my json codes in my php file and html file我应该如何在我的 php 文件和 html 文件中包含我的 json 代码
【发布时间】:2015-12-03 06:14:17
【问题描述】:

目前这些是我的代码。我的php页面:

$con = mysqli_connect($host, $username, $password, $db_name);
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");

$sql = "SELECT problem.id, problem.DateTimeCreated, status.status_desc, users.username FROM problem
                JOIN issue ON problem.issue_id = issue.id
                JOIN status ON problem.status = status.id
                JOIN users ON problem.reported_account_id = users.id
                where issue_id = '3'";

$result = mysqli_query($con,$sql);

echo '<table width="200" border="0" cellpadding="0" cellspacing="0">';
echo "<table>
      <tr>
      <th>Unique ID</th>
      <th>Date</th>
      <th>Status</th>
      <th>Reported by</th>
      </tr>";

while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['DateTimeCreated'] . "</td>";
    echo "<td>" . $row['status_desc'] . "</td>";
    echo "<td>" . $row['username'] . "</td>";

    echo "</tr>";
}
echo "</table>";

mysqli_close($con);

我的html代码:

<script>
function display(){
    var xmlhttp = new XMLHttpRequest();
    var url = serverURL() + "/gwifiv2.php";

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        }
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send();
}
</script>
</head>

<body>
<div data-role="page" data-theme="a">
    <div data-role="header" data-position="inline">
        <a href="index.html" data-icon="home" data-theme="a"><br></a>
        <h1>Issues</h1>
        <a href="domain.html" data-icon="arrow-l" data-theme="a"><br></a>
    </div>
    <div data-role="content" data-theme="a">
        <div data-role="main" class="ui-content">
            <table data-role="table" data-mode="columntoggle" class="ui-responsive ui-shadow" id="myTable">
                <thead>
                    <form>
                        <input type="button" value="Display" onclick="display()">
                    </form>
                    <tr>
                        <th>Unique ID</th>
                        <th data-priority="1">Date</th>
                        <th data-priority="2">Status</th>
                        <th data-priority="3">Ticket</th>
                    </tr>
                </thead>

我无法在我的 html 代码中显示从数据库中获取的 php 表。如果我直接输入我的 php 页面的 url,它将显示表格,但是当我将代码插入我的安卓设备时,表格不会显示。

【问题讨论】:

    标签: php html mysql json


    【解决方案1】:

    您必须定义一个div 或在哪里显示服务器点击响应。我稍微修改了您的 JavaScript 和 HTML 以正确呈现 AJAX 响应。

    这里是修改后的html

    <script>
    function display(){
        var xmlhttp = new XMLHttpRequest();
        var url = serverURL() + "/gwifiv2.php";
    
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
               document.getElementById("test").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", url, true);
        xmlhttp.send();
    }
    </script>
    </head>
    
    <body>
    <div data-role="page" data-theme="a">
        <div data-role="header" data-position="inline">
            <a href="index.html" data-icon="home" data-theme="a"><br></a>
            <h1>Issues</h1>
            <a href="domain.html" data-icon="arrow-l" data-theme="a"><br></a>
        </div>
        <div data-role="content" data-theme="a">
            <div data-role="main" class="ui-content">
                <table data-role="table" data-mode="columntoggle" class="ui-responsive ui-shadow" id="myTable">
                    <thead>
                        <form>
                           <input type="button" value="Display" onclick="display()">
                           <div id="test"></div>
                        </form>
                        <tr>
                            <th>Unique ID</th>
                            <th data-priority="1">Date</th>
                            <th data-priority="2">Status</th>
                            <th data-priority="3">Ticket</th>
                        </tr>
                    </thead>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-03
      • 2016-04-01
      • 2020-09-29
      • 2015-09-23
      • 2017-09-20
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多