Page 1 of 1

alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:12 pm
by brycekmartin
Hello gracious people of the forum. I'm trying to get a proof of concept down so that I can expand on it and create some really great functionality in some web apps using PHP, JSON, and JQUERY. I have two small pieces of code that send a JSON string to a php script which receives it and then returns a plain text string. Later I want to return JSON from PHP but that is for another exercise.

The problem I have is that my alert box is coming up and displaying my php script instead of the echo'd variable results.

HTML/Javascript

Code: Select all

 
<html>
<head>
<title> json and php test</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">
$(function(){
    var data = {"variable1":"data1"};
    $.post("getJSON.php",data,function(rdata){alert(rdata);},"text");
});
</script>
</head>
<body>
</body>
</html>
 

PHP Script

Code: Select all

 
<?php
 $res = json_decode($_POST['variable1'], true);
header("Content-type: text/plain");
 $ret = "done";
 echo $ret;
 
?>
 
Any Ideas?

Thanks
Bryce

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:28 pm
by kaszu
Looks like you haven't installed php?

Code: Select all

$res = json_decode($_POST['variable1'], true);
This is useless, because $_POST['variable1'] content is "data1", which is not valid json. See documentation.

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:32 pm
by brycekmartin
Yep. I've got a XAMPP stack running. when I type 127.0.0.1 in the browser I get the test page, so its working.

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:33 pm
by kaszu
If you open getJSON.php page in your browser, what do you get?

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:36 pm
by brycekmartin
A blank page.

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:41 pm
by kaszu
Use "View -> Page Source", there you should see you php code <- if you see it, then PHP is not installed (configured)

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:45 pm
by brycekmartin
well I must have a configuration issue... Any ideas on where to start to fix it?

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:46 pm
by kaszu
You should create a new topic for that. Here on devnet is a forum called "Installation and Configuration"

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 1:48 pm
by brycekmartin
Thanks, will do.

Re: alert showing php code instead of returned value

Posted: Wed Jul 22, 2009 2:01 pm
by brycekmartin
I was putting my stuff in the wrong htdocs folder. xampp has its own, but apache is pointing to its default one. PHP is installed.

Re: alert showing php code instead of returned value

Posted: Thu Jul 23, 2009 6:42 am
by JAB Creations
XAMPP is great at least for local WAMP development (I wouldn't use it live heh). In the Apache configuration file the htdocs directory is declared twice. If you declare two different paths it'll won't use the one you want. :wink: Also be sure to make a copy of a working configuration file! If you ever screw it up use a program like WinMerge to compare the working and broken copies. :)