In jQuery how would I get the 'itemName' for each in DATA and append it to posts-container?
so I would have html like this.....
title: wow just seen this
title: test
etc....
Thanks
Json
{
"ERRORS": [],
"DATA": [
{
"itemID": "012be513-9b2d-4ed6-9b84-4097a610a823",
"itemValidTo": "October, 29 2011 00:00:00",
"itemName": "wow just seen this",
"image": {
"imageCreated": "October, 06 2011 00:00:00",
"imageURL": "ha.jpg",
"imageID": "16fbdb40-8591-4a3b-b18e-bda494ac213f"
},
"itemActive": true,
"createdBy": {
"UserID": "DA1F154B-EF46-49BD-18C84C49478AD48E",
"accNumber": ""
},
"itemTxt": "SO impressed with this!",
"itemModified": "October, 06 2011 00:00:00"
},
{
"itemID": "30d2f2c1-58ca-4b3d-b3e0-d284ae5b25ab",
"itemName": "test",
"image": {
"imageCreated": "October, 05 2011 00:00:00",
"imageURL": "image.jpg",
"imageID": "bc869a94-fee5-4fc8-bd21-e2de2f020310"
},
"itemActive": true,
"createdBy": {
"UserID": "DA1F154B-EF46-49BD-18C84C49478AD48E"
},
"itemTxt": "test",
"itemModified": "October, 05 2011 00:00:00"
}
],
"MESSAGES": [
{
"TOTAL": 2,
"CURRENTPAGE": 1,
"TOTALPAGES": 1
}
]
}
script
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'get',
url: 'http://do.com/api/id/123',
dataType: 'json',
data: '',
success: function(r){
$('#waiting').hide(500);
var output = '';
//loop here and add append I assume?
开发者_JAVA百科 jQuery('#posts-container').append(output);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
}
});
return false;
});
$.each(r.DATA,function(key,value){
alert(value.itemName)
alert(value.itemID)
.
.
})
u can check from here http://jsfiddle.net/Uk5ZJ/
精彩评论