jQuery post方法和目录混淆

时间:2017-10-16 18:22:07

标签: php jquery post directory

通常,当我想更改页面时,我会使用href来执行此操作,或者我将使用标题功能。

对于我当前的项目,我需要使用jquery来接收和修改客户端输入的信息,然后我需要使用post方法让php能够访问所述信息。

收到信息后,我想在一个包含文件夹中使用单独的php文件对其进行操作,然后将用户重定向远离原始页面。

在处理项目时,页面不会改变,所以我想知道信息是否到达包含文件夹。

下面您将找到复制上述问题的代码的缩影示例。

按下保存按钮后,我希望jquery创建$ _POST [' message'],检查是否已设置,将其发送到changePage.inc.php页面,检查如果已设置,则再次将用户重定向到secondPage.php页面,该页面应显示" Hello World"。

名为index.php的文件

<?php
    session_start();
?>

<!DOCTYPE html>
<html>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"
    integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
    crossorigin="anonymous">
</script>
<script>
    $(document).ready(function(){
        $('#saveForm').submit(function(event){
            event.preventDefault();
            var message = "";

            var changeText = function(){
                message = "You wrote: " + $('#text').val();
            };

            var send = function(){
                if(message !== ""){
                    $.post("includes/changePage.inc.php", {message: message});
                    $.post("index.php", {message: message});
                }
            };

            changeText();
            send();
        });
    });
</script>
<?php
    if(isset($_POST['message'])){
        header("Location: includes.changePage.inc.php");
    }
?>
<body>
<textArea id="text"></textArea>
<form id="saveForm" action="includes/saveEssay.inc.php" method="POST">
  <button type="submit" id="saveButton">Save!</button>    
</form>
</body>
</html>

名为changeDirectory.inc.php的文件(在名为includes的文件夹中)

<?php

session_start();

if(isset($_POST['message'])){
    header("Location: ../secondPage.php");
}

exit();

名为secondPage.php的文件

echo 'Hello World';

第一条评论实际上并没有解决我的问题!

我需要从include文件夹中的php文件更改页面,所以我不想使用jquery重定向!

jquery在这里需要格式化文本并使其可以作为post变量访问,并且,一旦可以作为post变量访问,我希望运行changePage文件。

我不能强调这一点!重定向必须在changePage.inc.php文件中完成

0 个答案:

没有答案