javascript - 通过 Ajax 运行 php 脚本
问题描述
我正在建立一个新网站。
我自己在一个 linode 节点中托管它。该站点已经启动并运行。
我安装了 nginx 运行在 80 端口,apache 运行在 8001 端口。
我的问题是,当我进行 AJAX 调用时,响应(responseText)是整个 php 代码。我不明白如何让它通过 Apache 运行。
除了将端口更改为不与 nginx 冲突之外,我还没有对 apache 进行任何配置。
安装了apache2,安装了nginx。
function getSuccessOutput() {
$.ajax({
method: 'get',
url:'test.php',
complete: function (response) {
console.log(response.responseText);
$('#output').html(response.responseText);
},
error: function () {
$('#output').html('Bummer: there was an error!');
},
});
return false;
}
在控制台中,我得到了完整的 php 脚本。
PHP 以 echo $result 结束。如果我在服务器中使用 php -f 运行它,则结果正常。
我只需要responseText中的结果,稍后我会看到如何处理。
我不了解如何使代码在 apache 上运行,我知道它需要由某人解释,但我不知道该怎么做。
谢谢!
解决方案
检查您的 php 文件,如果文件开头有一个 open 标记:
<?php
不要使用短打开标签,因为它只有在使用 php.ini 配置文件中的 short_open_tag 启用时才可用。
<?
推荐阅读
- angular - 如何触发绑定数据的方法?
- reactjs - 使用 Material UI makeStyles 时键入的道具
- node.js - Node.js pm2 在 jenkins 管道中不起作用
- ruby-on-rails - 如何在activeadmin中更改页面标题
- multithreading - 强制挂起的函数在一个线程上工作以在后台映射 Realm 对象
- javascript - 包括多个未定义的变量
- c++ - 从较小的矩阵/向量构建矩阵
- python - 列出所有“.csv”文件名,然后输入相应的代码来绘制图形
- jsf - JSF 命令按钮未正确重定向
- sql - 识别表中的重复项并将重复记录踢到另一个表中