我已经看到有关此问题的问题和解答。例如How to return a HTML file as the response to a POST request?但我在实施解决方案时遇到问题。下面是一个名为websiteIssue的目录中的一些php代码示例,它不起作用,我不知道为什么。作为对POST请求的响应的HTML文件?
的index.php
if(isset($_POST['page']))
{
$page = $_POST['page'];
}
else
{
$page = "";
}
include 'case.php';
?>
case.php
$testLog = 'testLog.txt';
$fileHandle = fopen('testLog.txt', 'a');
fwrite($fileHandle, '$page = '.$page."\n";
switch($page)
{
case "screen2":
include 'screen2.php';
fwrite($fileHandle, 'including screen2.php'."\n");
break;
default:
include 'screen1.php';
fwrite($fileHandle, 'including screen1.php'."\n");
break;
}
fclose($fileHandle);
?>
screen1.php
screen1.phpScreen 1 => Screen2
function dataSubmit(data)
{
var xmlRequest = new XMLHttpRequest();
var formData= new FormData();
for(name in data)
{
formData.append(name, data[name]);
}
xmlRequest.open('POST', 'http://localhost/websiteIssue/');
xmlRequest.send(formData);
}
screen2.php
screen2.phpScreen 2 => Screen1
function dataSubmit(data)
{
var xmlRequest = new XMLHttpRequest();
var formData= new FormData();
for(name in data)
{
formData.append(name, data[name]);
}
xmlRequest.open('POST', 'http://localhost/websiteIssue/');
xmlRequest.send(formData);
}
在初始加载时,它按照我的预期工作,screen1.php中的html显示在浏览器中,但是当按下页面上的按钮时,html保持不变,而不是在screen2.php中更改为0122输出到testText.log是一样的东西:
$page =
including screen1.php
$page = screen2
including screen2.php
如同可能是显而易见的,我是一个新手到这一点,并希望有一些基本的东西我没有做过。我使用的浏览器是Firefox。任何帮助将非常感激。小提示:我为这篇文章手工重写了代码,并没有运行它(运行web服务器的机器没有连接到互联网),希望没有语法错误,但我可能犯了一个错字某处。
2016-06-15
Glenn