【问题标题】:Hosting web (Hello World) in Google Compute Engine VM (free trial) + Apache + Ajax + php + javascript在 Google Compute Engine VM(免费试用)+ Apache + Ajax + php + javascript 中托管网络(Hello World)
【发布时间】:2020-10-04 12:05:28
【问题描述】:

Hello World 在 Google Compute Engine VM(免费试用)上的实现包含以下文件:

index.php

<!DOCTYPE html>
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    function create () {
        $.ajax({
            url:"firestoreData.php",    //the page containing php script
            type: "POST",    //request type,
            success:function(result){
                console.log(result);
            },
            error: function(jqxhr, status, exception) {
                console.log("error:" + exception);
            }
        });
    }
</script>
<button type="button" onclick="create()">Click Me</button>
 </body>
</html>

firestoreData.php:

<?php
return "hello world";

问题是ajax的响应是php文件的内容:

<?php
return "hello world";

查看图片[1]

我尝试了几种方式的 php 文件,结果相同:

<?php
echo "hello world";
?>

...

<?php
echo "hello world";
exit;

... [1]:https://i.stack.imgur.com/qbpWb.png

【问题讨论】:

  • 好的,那么直接访问URL中的php文件会得到什么。
  • 完成后,您需要查看是否启用了 PHP。
  • 如果我直接访问 url 中的 php 文件,我得到相同的 php 文件的内容。我在我的虚拟机中安装了 php。你的意思是我需要启用?
  • 你是对的!!!! @蒂姆布朗劳!!!!请发布我想投票给你的答案!
  • 谢谢,但如果您展示了您为启用它所做的工作,如果它是其他人可能会错过并需要执行以使其工作的东西,那么它会更有意义。

标签: php ajax google-api google-compute-engine


【解决方案1】:

按照 TimBrownlaw 的建议,问题已解决,启用 php7(安装在我的 VM 中的版本)如下:

sudo apt-get install libapache2-mod-php7.4
sudo a2enmod php7.4

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多