alert showing php code instead of returned value
Posted: Wed Jul 22, 2009 1:12 pm
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
PHP Script
Any Ideas?
Thanks
Bryce
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;
?>
Thanks
Bryce