javascript - 使用没有 jquery 或 ajax 的纯 javascript 将 php 值传递给 modal
问题描述
是否可以使用 plain将值传递PHP
到模态框Javascript
?我在 SO 中进行了研究,发现大多数答案都是JQuery
or AJAX
。我想知道怎么做,因为我是新手Javascript
,PHP
所以我想在深入了解 and 之前先对 in 进行彻底的练习和Javascript
理解。JQuery
AJAX
我正在做一个小项目,它有一个模式框和一个<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">×</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
如果没有JQuery
and可以AJAX
吗?
我该怎么办?你能提供一些想法。
谢谢你。
解决方案
Ajax 是纯 JavaScript。但是,如果您只是想将 PHP 中的某些内容回显到客户端以作为 JavaScript 运行,那么您正在寻找json_encode
推荐阅读
- html - 内联块元素高度和可滚动内容框在 Angular 应用程序中的行为与 html-page 不同
- android - Android WebView播放视频报错闪黑屏
- c# - 在c#中提取路径的一部分
- angular - 从cordova(android/ios)访问站点时.net核心会话状态不保持
- spring - Spring Boot 和 Spring Data with Cassandra:在数据库连接失败时继续
- c# - 是否可以使用实体框架从 C# 中的多个表中获取连接 SQL 查询的结果?
- sql - 更新用于 SQL 报告的表中的批量数据的最佳实践
- git - 在 git 中,我如何验证错误修复是否在 Release 分支和 master 中
- php - 连接并搜索数据库,然后将其显示到网页?
- c# - System.Windows.Forms.dll 中抛出空引用异常