1

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":"tmimportertest100_(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.

1 Answer 1

2

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);
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.