我正在使用 JavaScript 中的 XMLHttpRequest 调用 file.php:
index.html
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.onload = function(){
console.log(xhr.responseText);
};
xhr.open("GET", "file.php", true);
xhr.send();
</script>
文件.php
<?php echo "123";
<小时/>
我预计123
作为结果字符串,但我得到了 <?php echo "123";
这是 file.php 的内容。
我使用XMLHttpRequest
吗?正确的?我错过了什么?
最佳答案
听起来您的服务器设置不正确并且没有使用 PHP 解析器执行脚本。
当您请求没有 XMLHttpRequest 的页面时(即只需在浏览器中输入 url)会发生什么?
关于javascript - 通过xmlHttpRequest获取file.php的执行结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37458872/