php - Ajax 返回 PHP 文本而不是解析代码
问题描述
本地环境为:Apache/2.4.34 (Unix) PHP/7.1.23 all conf。文件已经过检查和重新检查,并添加了额外的 cmd,例如:
<IfModule>
# PHP 7 specific configuration
....
</IfModule>
phpinfo() works fine etc.
xmlhttp 代码是:
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "php/getARCHIVE.php");
xmlhttp.setRequestHeader('Access-Control-Allow-Origin','localhost');
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
console.log(this.responseText);
} else {
console.log("Loading...");
};
}
}
并返回:加载中...
<?php
echo 'hi everyone!';
?>
作为文本!
或者 ......
$.ajax( {
url: 'php/getArchive.php',
crossDomain: true,
error: function( jqXHR, statusMessage, errorThrown){console.log('serverRequest for php:' + "\n" + statusMessage + "\n" + errorThrown);},
success: function( response, status, jqXHR ){
callback(response);
}
});
}
...返回相同的文本:
serverRequest for php:
parsererror
Error: Invalid XML: <?php
echo 'hi everyone!';
?>
随附的注释/错误是:“XML 解析错误:未找到根元素”
那么如何让服务器识别 .php 文件 - 这只是:
<?php echo 'hi everyone!'; ?>
i.e. the text that is being returned
解决方案
推荐阅读
- r - 来自非数值数据帧的平均值和 SD
- azure - 通过 ARM 模板部署时的 Azure 函数暂存槽交换错误
- google-bigquery - How to pass list of columns from one table to another table in bigquery
- java - 如何将 LinkedHashMap 转换为 Map
在 Java 中? - symfony - 动态延迟加载服务
- sql-server - SQL Server 在请求事务期间卡住了一张表
- ios - 如何以编程方式获取电话 (iOS) 提供商列表?
- ruby-on-rails - Rails:简洁地打印变量名称和
标签(如果存在) - node.js - 如何使用request-promise从nodejs中的HTTP GET请求获取字符串响应到变量
- python - 如何在没有全局变量的情况下将值传递给回调以进行匿名化?