最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery.get returning php code? - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Aug 9, 2009 at 2:46 giroygiroy 2,2536 gold badges28 silver badges38 bronze badges 1
  • What happens when you just hit the page php/getRocks.php? – Ryan Florence Commented Aug 9, 2009 at 4:01
Add a ment  | 

4 Answers 4

Reset to default 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 puter 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.

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.

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!

1st. make sure you have php installed

If you are using linux / apache2 and php 5 u need to pile/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./apache2php.html

发布评论

评论列表(0)

  1. 暂无评论