PDA

View Full Version : jQuery Ajax - returning PHP file contents


snoodle
03-20-2009, 04:53 PM
I recently had to reformat and reinstall everything from scratch. Now, the site I am building works fine on my provider's servers, but has a problem on my machine.

I am using JQuery/Javascript & PHP. It appears that upon returning from the server side PHP code, the data returned (echo'ed) is the complete contents of the php file (not the json data i'm passing out). This is happening for all ajax calls. I'm thinking this must be something in the the php.ini file, but don't know what.

A typical ajax caller and handler in my code looks like...

function jsFunction(){
obj.item1 = "item1_input";
obj.item2 = "item2_input";
var dataString = $.toJSON(obj);
alert("Before Update..... "+dataString);
$.post(handler.php', {data: dataString}, done_function);
}

function done_function(res){
alert(res);
}

Using this simple php code...

<?php
//
$res = json_decode($_REQUEST["data"], true);
// ...
// ... Processing and modifying contents of "data"
// ...
echo json_encode($res);
return 1;
?>

The value returned to the done_function (res) is the actual contents (code) of the php file, not the data that was echo'ed. Is this due to a setting in php.ini? This code worked fine before the crash and works fine on my provider's server.

Eldarrion
03-20-2009, 05:02 PM
Sounds more like... there is no php server running. Are you opening the site locally with a "file:///xampplite/htdocs/whatever.php" or with a "http://localhost/whatever.php"? If the latter... is your apache (or whatever) running with php support?

snoodle
03-20-2009, 05:21 PM
Yeah, phpMyAdmin isn't working either. It did at one point since that was how I imported the database from my host's server. When I try to run phpMyAdmin I get, "Cannot load mysqli extension. Please check your PHP configuration. - Documentation".

The Apache modules include php5_module. What else should I check? Should I just reinstall WAMP or... do you know how I get php back? (I'd rather learn something than just blindly try it again).

Eldarrion
03-20-2009, 05:37 PM
Remotely? Doubtful. You could always ask in the PHP forums instead, might get a better reply... or rather in the software forum, considering the question isn't related to PHP coding, but to the installation and running of Apache with PHP support.

snoodle
03-20-2009, 06:32 PM
Strange. I reinstalled WAMP. phpMyAdmin comes up fine but my jquery ajax calls are still returning the contents of the php file being summoned. I'm losing it.

DaveA
11-22-2009, 12:41 PM
I had this problem too. The php script was being returned instead of the expected echoed value.

I had upgraded from php4 to php5.

The problem was caused by myself using a combination of long and short tags.

In the php.ini file for php5 'short_open_tag' was set to 'off'

The solution is either 'do not use short tags' of set 'short_open_tag' to 'on'

Hope this helps

snoodle
11-22-2009, 05:59 PM
it's been so long i forgot how i solved the problem. i know i've run into the tag problem at least once before. anyway, thanks for the reply.