3

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.

1
  • What happens when you just hit the page php/getRocks.php? Commented Aug 9, 2009 at 4:01

4 Answers 4

8

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

actually, to be clear above, I should have used example lib/getRocks.php or subdir/getRocks.php as compared to php/getRocks.php (the idea that it's the subdir that's the problem, not anything with php in particular)
0

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!

1 Comment

If you are going to C:\My Websites\something.php then it won't process the php. You have to access it from your server at localhost or wherever your files are.
0

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

7 Comments

I do use apache and already have that line in the conf file. I don't think its an issue with my server setup cause this used to work fine with plain javascript. This has only started happening since i started messing around with jquery
opening php/getRocks.php directly in your browsers will also tell something if everything oks.
When I try to access it from the browser, I also get the php code back :(
meaning, it has nothing to do with jQuery :/
maybe it s time to recheck your installations,configurations for apache+php
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.