【发布时间】:2013-11-01 16:37:06
【问题描述】:
我有一个非常简单的 hello world ajax-php 示例,它作为结果返回整个 php 脚本。这是代码:
客户端代码:
$.ajax({
type: "GET",
contentType: "text",
url: "hello-world.php",
success: function(data){
$("#myDiv").text(data);
console.log(data);
}
});
服务器代码:
<?php
// A simple web site in Cloud9 that runs through Apache
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console
echo 'Hello world!';
?>
这是控制台日志:
<?php
// A simple web site in Cloud9 that runs through Apache
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console
echo 'Hello world!';
?>
谢谢!
【问题讨论】:
-
您确定服务器上启用了 PHP 吗?如果你直接在浏览器中打开 hello-world.php 你会看到什么?
-
脚本在直接访问时运行并打印“Hello World!”。我正在使用 cloud9 工作区来运行这个示例。
-
Zakiya,你的预期输出是多少??
-
你调用 AJAX 的 URL 是否相同,即“发送到控制台输出选项卡的 URL”?