【发布时间】: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;
【问题讨论】:
-
好的,那么直接访问URL中的php文件会得到什么。
-
完成后,您需要查看是否启用了 PHP。
-
如果我直接访问 url 中的 php 文件,我得到相同的 php 文件的内容。我在我的虚拟机中安装了 php。你的意思是我需要启用?
-
你是对的!!!! @蒂姆布朗劳!!!!请发布我想投票给你的答案!
-
谢谢,但如果您展示了您为启用它所做的工作,如果它是其他人可能会错过并需要执行以使其工作的东西,那么它会更有意义。
标签: php ajax google-api google-compute-engine