当我把php文件移到一个文件夹中时,为什么 AJAX 不能得到我的php文件?[closed]

wmtdaxz3  于 2023-01-12  发布在  PHP
关注(0)|答案(1)|浏览(118)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
2天前关闭。
Improve this question
目前我有一个index.php页面,看起来像这样:

这是我的代码:
index.php:

<div style="width: 90%; margin:0 auto;">
        <form class="mb-3" style="width: 150px;">
            <label for="floor">Floor:</label>
            <select class="form-select" name="floor" id="floorSelect" onkeyup="filterByFLoor()">
                <option value="" selected>All Floors</option>
                <?php
                $sql = "SELECT * FROM d_floor";
                $floors = mysqli_query($conn, $sql);
                while ($floor = mysqli_fetch_array($floors, MYSQLI_ASSOC)):
                    ;
                    ?>
                    <option value="<?php echo $floor['fname']; ?>">
                        <?php echo $floor['fname']; ?>
                    </option>
                <?php endwhile; ?>
            </select>
        </form>
</div>

<div id="displayTable" class="mt-3" style="width: 90%; margin:0 auto;"></div>

<script src="tables/table.js"></script>

<script>
function filterByFloor() {
            var selectJob = document.getElementById("floorSelect"),
                table = document.getElementById("displayTable"),
                tr = table.getElementsByTagName("tr");

            for (var i = 1; i < tr.length; i++) {

                floor = tr[i].getElementsByTagName("td")[9]; // use [0] as the first `td`
                console.log(floor);

                if (floor && floor.innerHTML.indexOf(selectJob.value) > -1) {
                    tr[i].style.display = "";
                } else {
                    tr[i].style.display = "none";
                }

            }
        }

        // listen to select changes
        document.querySelector('#floorSelect').addEventListener('change', function (e) {
            filterByFloor();
});
</script>

table.js:

//display open table
function displayOpen() {
    var displayOpen = "true";
    $.ajax({
        url: "open.php",
        type: 'post',
        data: {
            displaySend: displayOpen
        },
        success: function (data, status) {
            $('#displayTable').html(data);
        }
    })
}

open.php:

<h2>OPEN</h2>
<?php
// date_default_timezone_set('Asia/Jakarta');
// $currentDateTime = date('Y-m-d H:i:s');
// echo $currentDateTime;
include 'database/connect.php';

if (isset($_POST['displaySend'])) {
    $table = '<table class="table table-sm table-bordered table-striped table-hover">
                <thead class="text-center align-middle">
                    <tr>
                        <th scope="col">NO</th>
                        <th scope="col">DETAILS</th>
                        <th scope="col">MODEL</th>
                        <th scope="col">PIC</th>
                        <th scope="col">OPEN DATE</th>
                        <th scope="col">TARGET DATE</th>
                        <th colspan="3" scope="col">REMARKS</th>
                        <th scope="col">FLOOR</th>
                        <th scope="col">ACTION</th>
                    </tr>
                </thead>
                <tbody class="table-group-divider" style="font-size:0.9rem;">';
    $sql = "SELECT * FROM d_mom WHERE status='OPEN' ORDER BY opendate DESC";
    $result = mysqli_query($conn, $sql);
    $number = 1;
    while ($row = mysqli_fetch_assoc($result)) {
        $id = $row['momid'];
        $details = $row['momdetails'];
        $model = $row['model'];
        $pic = $row['pic'];
        $opendate = $row['opendate'];
        $targetdate = $row['targetdate'];
        $remarks = $row['remarks'];
        $updatedate = $row['updatedate'];
        $updateby = $row['updateby'];
        $floor = $row['floor'];
        // $status = $row['status'];
        $table .= '
                    <tr>
                    <td scope="row" class="text-center">' . $number . '</th>
                    <td>' . $details . '</td>
                    <td class="text-center">' . $model . '</td>
                    <td class="text-center">' . $pic . '</td>
                    <td class="text-center">' . $opendate . '</td>
                    <td class="text-center">' . $targetdate . '</td>
                    <td>' . $remarks . '</td>
                    <td class="text-center">Updated on: ' . $updatedate . '</td>
                    <td>By: ' . $updateby . '</td>
                    <td class="text-center">' . $floor . '</td>
                    <td class="text-center">
                        <div class="dropdown">
                            <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                Action
                            </button>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="#">Update</a></li>
                                <li><a class="dropdown-item" href="#" onclick="updateToUM(' . $id . ')">Under Monitoring</a></li>
                                <li><a class="dropdown-item" href="#" onclick="updateToClosed(' . $id . ')">Closed</a></li>
                                <li><a class="dropdown-item" href="#" onclick="deleteMoM(' . $id . ')">Delete</a></li>
                            </ul>
                        </div>
                    </td>
                </tr>';
        $number++;
    }
    $table .= '</tbody>
               </table>';
    echo $table;
}

?>

使用上面的代码,我可以显示如图所示的表格,但是当我把open.php放入tables文件夹时,它将不再显示表格,我尝试将url改为tables/open.php/tables/open.php../tables/open.phpmom_tracking/tables/open.php,但是没有任何效果。

3htmauhk

3htmauhk1#

您是否将所有相关的部分移动到新的tables文件夹中?例如,在open.php中,您有这样一行:

include 'database/connect.php';

database目录是否存在于open.php旁边的新位置?
然后在table.js中调整此线:

url: "open.php",

使用完整URL或绝对路径,即

url: "/tables/open.php",

url: "https://yoursite.com/wherever/tables/open.php",

如果你像JSON( AJAX )请求那样在浏览器中打开这个页面,它会输出预期的结果吗?没有错误吗?

相关问题