【问题标题】:Run php script through Ajax通过 Ajax 运行 php 脚本
【发布时间】:2019-01-06 16:56:58
【问题描述】:

我正在建立一个新网站。

我自己在一个 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 运行它,输出结果 OK。

我只需要responseText中的结果,稍后我会看到如何处理。

我不明白如何让代码在 apache 上运行,我知道它需要有人解释,但我不知道该怎么做。

谢谢!

【问题讨论】:

标签: javascript php apache nginx


【解决方案1】:

检查你的php文件,文件开头是否有open标签:

<?php

不要使用短打开标签,因为它只有在使用 php.ini 配置文件中的 short_open_tag 启用时才可用。

<?

【讨论】:

    猜你喜欢
    • 2015-06-26
    • 2021-06-04
    • 2011-07-27
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    相关资源
    最近更新 更多