【问题标题】:AJAX GET returns the php scriptAJAX GET 返回 php 脚本
【发布时间】: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”?

标签: php jquery ajax get


【解决方案1】:

根据@DavidRiccitelli - 看起来您没有运行 php,而 apache 只是提供文件而不是将其传递给 PHP 以执行。

尝试XAMPPWAMP 服务器在Windows 上捆绑服务器包 MAMP 用于 MacOSX etx

【讨论】:

    【解决方案2】:

    您的 PHP 可能没有被解释,因此被作为原始 HTML 返回。

    查看here for a similar issue.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 1970-01-01
      • 2012-10-02
      • 2015-12-09
      • 2014-10-18
      • 1970-01-01
      相关资源
      最近更新 更多