【发布时间】:2018-06-04 04:39:26
【问题描述】:
我正在使用这个问题jQuery Ajax POST example with PHP 来了解如何在提交表单之前处理表单中的数据。
我有一个没有 GUI 的应用程序,我围绕它构建了一个数据库和一个 web 应用程序。 此应用程序使用 fopen() 打开 xml 文件。 我正在使用 $GET 方法从数据库的列中获取 xml 文件及其路径。
<?php
$sql = pg_query($conn, "select link, identification from tbl_xml where date='$today';"));
?>
<form id="xmlform" name="xmlform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="GET">
<?php
while ($row = pg_fetch_row($sql)) {
echo "<button type='submit' name='xml' value='$row[0]' class='btn-as-link'>$row[1]</button>"
}
?>
</form>
我们在index.php中。
[...]
ELSE IF( isset($_GET['xml'] )){
include_once("showXml.php");
}
[...]
showXml.php:
$url = filter_var($_GET['xml'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH);
[...]
// $url contains a really long path and the file. Each folder of the path creates exception on how to open the xml file, but in the end i simply open like this:
// Opening the file
$myfile = fopen("$xml", "r");
$xml = fread($myfile,filesize("$xml"));
$dom = new DOMDocument;
$dom->preserveWhiteSpace = TRUE;
// IF the file has XML format we will arrange it, if not we will print it raw
IF ( $dom->loadXML($xml) ) {
$dom->formatOutput = TRUE;
$xml_out = $dom->saveXML();
echo "<pre><code class='language-markup'>";
echo htmlspecialchars($xml_out);
echo "</code></pre>";
} ELSE {
$xml = str_replace('\'','\''.PHP_EOL,$xml);
echo "<pre><code class='language-markup'>";
echo htmlspecialchars($xml);
echo "</code></pre>";
}
fclose($myfile);
我想使用 $GET 方法,因为 webapp 有一个时钟,页面每 X 分钟刷新一次。如果我使用 $POST,我会看到那个窗口告诉我“重新发送数据”。我不想那样。
我面临的问题是路径在 URL 中很明显,并且因为 webapp 将很快收到更新,它还将打开其他服务器中的 XML 文件,我正在寻找一种方法来维护 @ 987654326@ 但将表单从使用 $GET 方法转换为 jquery/ajax 或任何其他方式以将其 xml_file_path 提供给 showXml.php。
我添加了另一个问题的代码,我可以阅读“万岁,它成功了!”在控制台上。
我的变量$xml 在form.php 内。
form.php
if (isset($_POST['xml']){
$xml = isset($_POST['xml']) ? $_POST['xml'] : null;
}
从这里开始,我不清楚如何触发:
ELSE IF( isset($_GET['xml'] )){
include_once("showXml.php");
}
index.php 中,打开变量$xml 不是来自$GET 方法,而是来自$POST 内部使用的form.php
【问题讨论】:
-
我不知道你怎么能没有 gui 但有一个按钮?
-
这是一个运行在 Ubuntu 服务器上的 java 应用程序。应用程序本身没有 GUI。它根据谁向我发送了文件来创建文件夹。我建立了一个数据库,并且太多的 bash 脚本无法在数据库中注册所有发送和接收的文件。 webapp 向我展示了这些文件
-
@SergeK.,好吧,不是真的。我使用 include 是因为这是我很久以前对网站进行编程的方式。现在我必须在同一个服务器之外打开 xml 文件,我仍然可以使用 include 和 $GET,但是你能想象这个 URL:
index.php?xml=100.100.100.99:5050/rootfolder/basefolder/anotherfolder/evenonemore/dateoftoday/xmlfile.xml我确定有一个正确的方法,我只是不知道): -
$.get('100.100.100.99:5050/rootfolder/basefolder/anotherfolder/evenonemore/dateoftoday/xmlfile.xml', ...?