Hi,
Im having difficulty getting my form contents to send to my php page using ajax, jquery and json. The results just doesnt want to show.
My javascript, where I create the JSON object and try to send it through to the php page:
var JSONobj;
var JSONstr;
function createJSON(){
JSONobj = {
firstname : $('#firstname').val(),
surname : $('#surname').val(),
age : $('#age').val(),
email : $('#email').val()
};
JSONstr = JSON.stringify(JSONobj);
}
$(document).ready(function() {
$('#submit').click(function(e){
e.preventDefault();
createJSON();
$.post("save.php", {data:JSONstr}, function(result){ alert(result);}, "json");
});
});
The php page:
<?php
$tmp = json_decode($_POST["data"]);
echo $tmp['firstname'];
?>
What should happen is the firstname should be alerted. But the alert box doesnt even show and I find no errors using firebug...
Thanks in advance