jquery.get返回php代码?

I am trying to use jquery's ajax $.get(...) function to send a request to my server and have it return some data. I am using the following code:

$.get("php/getRocks.php", { name: "John", time: "2pm" },
    function(data){
    alert("Data Loaded: " + data);
});

Instead of getting the the data back, it just returns the entire php file as a string. Am I doing something wrong? Thanks for the help.

Is PHP installed on your server? This is a server issue. For some reason your .php file isn't being handled properly and it is returning the PHP code in plain text.

This is in response to:

Well, I seem to have solved the problem, sort of. Apparently, if I access the site localy, php doesn't work, but if I use the domain name, it does. Anyone know why? Or better yet, a way to fix this?

Thanks to everyone for the help!

When working locally (and it always is a good idea to do so before uploading to a live environment) you need to setup PHP on your computer so that it can run the pages you require. A browser will not do it for you as it is a server side technology. You can download a package like Uniform Server, that will give you a full server environment for you to work with.

1st. make sure you have php installed

If you are using linux / apache2 and php 5 u need to compile/install apache and load php via dso eg:

LoadModule php5_module        modules/libphp5.so

In my humble opinion it has got nothing todo with your jQuery but your web server installation/config:

If it is apache make sure you add this line in your conf file:

AddType application/x-httpd-php .php

More reading about php and apache if you are using php anad apache in linux/nix eg: http://dan.drydog.com/apache2php.html

Well, I seem to have solved the problem, sort of. Apparently, if I access the site localy, php doesn't work, but if I use the domain name, it does. Anyone know why? Or better yet, a way to fix this?

Thanks to everyone for the help!

I have the same problem (using MAMP on mac), and while I haven't solved it, I am a step closer.

Basically, it would appear to have something to do with subdirectories/document root. If I set my url as getRocks.php (and move my script there), it works (I get content back), but if I get it as php/getRocks.php, it does not work (I get the php code back).

Perhaps MAMP is doing something add with response types within subdirectories? Am going to take a further look, but hopefully this helps lead you in the right direction.