首页 > 解决方案 > 使用没有 jquery 或 ajax 的纯 javascript 将 php 值传递给 modal

问题描述

是否可以使用 plain将值传递PHP模态框Javascript?我在 SO 中进行了研究,发现大多数答案都是JQueryor AJAX。我想知道怎么做,因为我是新手JavascriptPHP所以我想在深入了解 and 之前先对 in 进行彻底的练习和Javascript理解。JQueryAJAX

我正在做一个小项目,它有一个模式框和一个<table>带有编辑控件的。

<div id="modalBox" class="w3-modal">
    <div class="w3-modal-content">
        <div class="w3-container">
            <span onclick="document.getElementById('modalBox').style.display='none'" class="w3-button w3-display-topright">&times;</span>
            <p>Some text. Some text. Some text.</p>
            <p>Some text. Some text. Some text.</p>
        </div>
    </div>
</div>

<div class="record-container">
    <table class="table-record">
        <tr>
            <th>Title</th>
            <th>Date Created</th>
            <th>Control</th>
        </tr>

        <?php
        $announcementDaoImpl = new AnnouncementDaoImpl($pdo);
        $announcementList = $announcementDaoImpl->getAllAnnouncementByMostRecent();
        foreach($announcementList as $key => $value): ?>
        <tr>
            <td><?php echo $key->getTitle(); ?></td>
            <td><?php echo $value->getDateAdded(); ?></td>
            <td>
                <a href="#" onclick="showEditModal('modalBox')">Edit</a>
            </td>
        </tr>
     <?php endforeach; ?>
    </table>
</div>

假设我想用返回的值填充模态框,$value->getDateAdded如果没有JQueryand可以AJAX吗?

我该怎么办?你能提供一些想法。

谢谢你。

标签: javascriptphpjqueryajax

解决方案


Ajax 是纯 JavaScript。但是,如果您只是想将 PHP 中的某些内容回显到客户端以作为 JavaScript 运行,那么您正在寻找json_encode


推荐阅读