如何使用jscript和php更改php读取文件.新Q如何阻止它影响标头


How to change a php read file using jscript and php. New Q how to stop it effecting the header

注意,这仍然不能按预期工作,它没有将信息放入页面中,而是重定向到新页面

更新新的问题是,我不希望用户看到一个巨大的标题,这就是我使用这个readfile系统的原因。当我更改contentFile时,有什么方法可以避免巨大的标题吗?提前感谢这从.htaccess文件中可行吗?还是这不是的一个选项

提前感谢

我的问题是,是否可以使用ajax、jscript或html更改readfile。因此,如果用户单击php中的按钮,它会更改读取文件

示例

//display content    
<?php
    $contentFile = "content.php";
    readfile( $contentFile );
?>

重定向

<script type="text/javascript">
   document.getElementById("myButton").onclick = function () 
{
                       location.href = "./content2.php";
};
</script>
    <p>TO POPULATE THE TABLES CLICK THE BUTTON: 
           <button id="myButton2" class="float-left submit-button" >changecontent</button></p>
                        </br>
   //

任何帮助都将是惊人的

更新以下的工作代码

  <section id="content" class="content">
    <button id="newButton" class="float-left submit-button" >changecontent</button></p>
        </br>
    <?php
    if(isset($_GET['filename'])){
        $contentFile = $_GET['filename'];
    }else{
        $contentFile = 'content.';
    }
    readfile( $contentFile.'php' );
    ?>
    <script type="text/javascript">
        document.getElementById("newButton").onclick = function()
    {
        location.href= "test.php?filename=content2.";
    };  
    </script>
</section>
Try this logic
 PHP code...
 if(isset($_GET['filename'])){
     $contentFile = $_GET['filename'];
 }else{
     $contentFile = 'content1';
 }
 readfile( $contentFile.'.php' );
<script type="text/javascript">
   document.getElementById("myButton").onclick = function () 
{
      location.href = "change_file.php?filename=content2";
};
</script>

您分配了错误的id,请使用以下javascript。

<script type="text/javascript">
   document.getElementById("myButton2").onclick = function () 
{
                       location.href = "./content2.php";
};
</script>

希望这能帮助您