I have a request.json in mootools to get some data from a php function returning the following:
{"userID":"1",
"userName":"Ezra",
"total":5,
"listItems":[
{"sessionID":"9",
"sessionName":"tmimportertest100_(9-1_100)",
"sessionCount":100,
"sessionDC":"12:11AM - Jun 06 11",
"sessionDM":"01:00AM - Jan 01 70",
"sessionActive":"1"},
{"sessionID":"10",
"sessionName":"tmimporterte开发者_JAVA技巧st100_(10-1_100)",
"sessionCount":100,
"sessionDC":"05:04PM - Jun 06 11",
"sessionDM":"01:00AM - Jan 01 70",
"sessionActive":"1"}]}
I need to setup a loop to insert a listItem into a div for each "set" of data from "sessionID" to "sessionActive".
var req = new Request.JSON(
{
url: 'ajax.php?action=getSessions',
onSuccess: function(session)
{
// ????
}
}).send();
the info on the Mootools website is a lil confusing on this stuff, I know basicly howto inject elements and create them.. but accessing the json and creating a for loop around it.. #confused#
Thanks for your helps.
You access the json data as a normal javascript object.
onSuccess: function(jsonData){
var container = document.id('container');
var items = jsonData.listItems;
Array.each(items, function(row){
new Element('div').adopt(
new Element('h1', {text:row.sessionName}),
new Element('h2.count', {text:row.sessionCount})
).inject(container);
});
}
精彩评论