RSS

Parse JSON with JQuery

29 Oct

JSON file – json.php

<?php
$json = '{ "students":[

{
"id":"001",
"name" :{"first" : "rahul", "last" : "mani"},
"age" : 20,
"city" : "hydrabad"
},
{
"id":"002",
"name" :{"first" : "deepu", "last" : "patel"},
"age" : 18,
"city" : "delhi"
}
]}';
echo $json;
?>

 


<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var url = "json.php";
$.getJSON(url,function(json){
$.each(json.students,function(i,student){
$("#response").append(
student.id + ' '+ student.name.first + ' ' + student.age + ' ' + student.city + '<br>'
);
});
});
});
</script>
</head>
<body>
<div id="response"></div>
</body>
</html>
Advertisements
 
Leave a comment

Posted by on October 29, 2012 in JavaScript, jQuery

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: