I've been comparing my code to other examples on the web and I still can't find my errors.
When I load the page and click submit, nothing happens on the screen. However, in Firebug I receive the POST 200 OK and the PHP script that should be on screen is spelled out in the POST response tab.
Since Firebug is responding appropriately, I am confused as to what is wrong.
Basic HTML form
<form id="form" action="" method="post">
<input type="submit" name="submit" id="submit" value="submit"/>
</form>
<div id="results"></div>
jQuery creates a JS object. The object is sent through JSON.stringify and JSON.parse. The submit event handler fires off the $.ajax. JSON data is passed to ok.php and it should return the PHP info called in the script, in theory.
var addIt = new Object();
addIt.one = "one";
addIt.two = 2;
addIt.three = addIt.one +" + "+ addIt.two +" = "+ "three";
$jsonAddIt = JSON.stringify(addIt);
$jsonAddIt = JSON.parse($jsonAddIt);
$('#submit').click(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'ok.php',
dataType:'json',
data: ({ json:$jsonAddIt }),
success:function(data) {
$("#results").html(data);
}
});
});
PHP
<?php
$ajaxInfo = $_POST["json"];
if ($ajaxInfo !="")
{
echo "info transfered";
}
else
echo "nothing";
?>
<div id="returned">
<?php print_r($ajaxInfo); ?>
</div>