PHP AND JSON problem..
Posted: Sat Aug 20, 2011 8:32 am
I am new to JSON and PHP. I cant get the data with JSON object using jquery. Cud anybody pls have a look at y code-
this is the ajax.php
Code: Select all
<html>
<head>
<script type="text/javascript" src="jquery-1.6.1.js"> </script>
<script type="text/javascript">
$(document).ready( function () {
$("form").submit( function () {
$.post(
"ajax.php",
$("#myFrm").serialize(),
function(result){
alert(result.name); // nothing showing here....
//$("#ajaxDiv").html(result);
} , "json"
);
return false;
});
});
</script>
</head>
<body>
<div id="ajaxDiv"> AJAX REQUEST</div> <br>
<form id="myFrm" method="post">
<input type='text' name='a' value='TANVIR' />
<input type='text' name='b' value='EMRAN' />
<input type='submit' />
</form>
</P>
</body>
</html>Code: Select all
<?php
$json = array(
'name' => 'HOSSAIN',
'age' => '22',
'location' => 'DHAKA'
);
echo json_encode($json);
?>