【发布时间】:2017-06-28 09:05:15
【问题描述】:
我正在运行 XAMPP 和 Apache。我有两个文件:
index.php
<html>
<head>
<title>php script</title>
</head>
<body>
<?php
header("Access-Control-Allow-Origin: *");
echo "hello world";
?>
</body>
</html>
post.html
<html>
<head>
<title>html page</title>
</head>
<body>
<script>
var xhr;
xhr=new XMLHttpRequest();
xhr.open("POST", "http://localhost/demoApp/index.php", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send();
</script>
</body>
</html>
我希望 post.html 调用 index.php 以便 post.html 在 html 页面上显示“hello world”。当我打开 index.php 时,我看到“hello world”。
我也知道 post.html 正在调用 index.php 因为我有其他脚本,当复制到 index.php 时会成功如果我打开 post.html,请给我发送电子邮件。
如果 post.html 确实在调用 index.php,为什么我的回显没有显示在 post.html 上?
【问题讨论】: