AJAX GET返回的PHP脚本脚本、AJAX、GET、PHP

2023-09-10 20:39:13 作者:事业是男人的根基

我有一个返回结果,整个PHP脚本一个非常简单的Hello World Ajax的PHP的例子。这里的code:

I have a very simple hello world ajax-php example that returns as a result the whole php script. here's the code:

   $.ajax({
        type: "GET",
        contentType: "text",
        url: "hello-world.php",
        success: function(data){
            $("#myDiv").text(data);
            console.log(data);
        }

    });

服务器code:

<?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是不是跨preTED,因而被返回原始的HTML。

Chances are your PHP isn't being interpreted, and thus is being returned as raw HTML.

检查here对于类似的问题。