问题
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