Post 在不重新加载页面的情况下,表单与 iframe 的会话?

Post Form with Session to iframe without reloading page?

这是我正在尝试执行的操作(无需重新加载页面):

  1. 制作表格
  2. 提交并打开iframe(iframe.php)
  3. 将输入值放入变量
  4. 将变量放入会话
  5. 将会话变量传递给 ajax.php
  6. 从 iframe.php 向 ajax.php
  7. 发出 ajax 请求
  8. 同时显示加载 gif
  9. 在 iframe 中显示 ajax 调用的结果
  10. 隐藏加载 gif。

我唯一的问题是,我不知道如何在不重新加载页面的情况下提交表单,所以我可以将值传递给变量,然后传递给会话。

这是我的简写代码:

MainPage.php:

<?php
    session_start();
    if (isset($_POST['Submit'])) {
        $_SESSION['Flightnumber1'] = $_POST['Flightnumber1'];
        $_SESSION['Datetime1'] = $_POST['Datetime1'];
    }
?>
<form target="iframe" method="post" action="iframe.html">
    <input id="Flightnumber1" name="Flightnumber1" type="text" />
    <input id="Datetime1" name="Datetime1"  type="text"/>
    <input id="Submit-Prufbox" name="Submit" type="submit" onclick='document.getElementById("iframe").src="iframe.php"; $("#iframe").show();' />
</form>
<iframe id="iframe" name="iframe" style="display: none;"></iframe>

iframe.php:

 <?php
    session_start();
 ?>

    <script src="js/jquery/jquery.min.js"></script>

    <div style="display: none;" id="cover" style="position: fixed; height: 100%; width: 100%; top:0; left: 0; background: #FFFFFF; z-index:99999; font-size: 60px; text-align: center; padding-top: 200px; color: #247AFC; user-select: none;-moz-user-select: none;-khtml-user-select: none;-webkit-user-select: none;-o-user-select: none;"><img src="PageImages/loading.gif" /><br />Flug wird gepr&uuml;ft</div>
                <script language="javascript" type="text/javascript">
                    $(document).ready(function(){
                        $('#php').load('Rechner.php', function() {
                            $("#cover").fadeOut(1500);
                        });
                    });
                </script>
    <div id="php"></div>

ajax.php:

<php 
    session_start();
    echo $regValue = $_SESSION['Flightnumber1'];
    echo $regValue2 = $_SESSION['Datetime1'];
?>

我希望有人能理解这个乱七八糟的东西,但我真的不知道如何解释这个更普通的东西,因为它真的很复杂。

您已经在使用 jQuery。

使用 jQuery.post().

提交带有 ajax 的表格

这是文档和示例:https://api.jquery.com/jquery.post/