AJAX GET returns the php script

梦想的初衷 提交于 2020-01-05 09:18:48

问题


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

client code:

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

    });

server 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!';

?>

here's the console log:

<?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!';

?> 

thanks!


回答1:


As per @DavidRiccitelli - it looks like you're not running php and apache is just serving up the file rather than passing it to PHP to be executed.

Try WAMP server of XAMPP for bundled server packages on windows MAMP for MacOSX etx




回答2:


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

Check here for a similar issue.



来源:https://stackoverflow.com/questions/19731157/ajax-get-returns-the-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!