在Google Compute Engine VM(免费试用版)和#x2B;阿帕奇&x2B;Ajax+;php+;javascript

在Google Compute Engine VM(免费试用版)和#x2B;阿帕奇&x2B;Ajax+;php+;javascript,php,ajax,google-api,google-compute-engine,Php,Ajax,Google Api,Google Compute Engine,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

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>

PHP测试
函数创建(){
$.ajax({
url:“firestoreData.php”//包含php脚本的页面
类型:“POST”,//请求类型,
成功:功能(结果){
控制台日志(结果);
},
错误:函数(jqxhr、状态、异常){
日志(“错误:+异常”);
}
});
}
点击我
firestoreData.php:

<?php
return "hello world";

根据TimBrownlaw的建议,问题在启用php7(安装在我的VM中的版本)时得到了解决,如下所示:

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

好的,如果你直接访问URL中的php文件,你会得到什么?一旦你这样做了,你需要看看你是否启用了php。如果我直接访问URL中的php文件,我会得到相同的php文件内容。我在虚拟机中安装了php。你说我需要启用是什么意思?你说得对@廷布罗恩劳!!!!请张贴我想投你一票的答案!谢谢,但是如果你展示了你为实现它所做的事情,如果其他人可能会错过它,并且需要执行才能使它工作,那么它就更有意义了。
<?php
echo "hello world";
?>
<?php
echo "hello world";
exit;
sudo apt-get install libapache2-mod-php7.4
sudo a2enmod php7.4