Hi,
I'm a beginner.
I write simple json jquery php code to help understand the idea of json, but its not work, please help me.(I didnt write $_Post, submit, click function etc.. because its not working with, soo I cut the code to find the problem)
The user enters view.html and should get an alert box with value Bob - the problem is the user doesn't get the alert box.
view.html
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: 'controller.php',
type: 'post',
dataType: 'json',
success: function (data) {
alert(data["userdata"]["first"]);
}
});
});
</script>
</head>
<body>
</body>
</html>
controller.php:
<?php
$arr=array();
$arr['userdata']['first']='Dan';
echo json_encode($arr);
?>
Thanks for help