1

I have this output that I got from my PHP page:

{"schedules":{"Event_Date":"2011-03-12","Meet_Name":"Time Trials ","Duration":"9:00am-12:00pm","Location":"Agoura High School","Address":"28545 Driver Ave","City":"Agoura Hills","State":"CA","Postal":"91301"}}

I would like to render this output as HTML using this Javascript code:

var serviceURL = "http://localhost/";

var schedules;

$('#Schedule').bind('pageinit', function(event) {
getScheduleList();
});

function getScheduleList() {
    $.getJSON(serviceURL + 'get_Mobile_Schedule.php', function(data) {
        $('#schedulelist li').remove();
        schedules = data.items;
        $.each(schedules, function(index, item) {
            $('#schedulelist').append('<li><h4>' + item.Event_Date +'</h4>'
                    ); 
        });
        $('#schedulelist').listview('refresh');
    });
}

But it seems that I cannot get anything to render.

Does anyone have any suggestions?

Thanks!

1
  • 1
    firebug is good friend , also check that you are sending json headers ,before you echo the string. Commented Mar 28, 2012 at 15:06

3 Answers 3

2

schedules = data.items - data does not contain a property named items. You probably want schedules = data.schedules instead.

Sign up to request clarification or add additional context in comments.

Comments

0

Your JSON has an extra '}' at the end. JQuery won't recognize it if it's malformed.

Also, bindings should happen within the jquery 'ready' function. Try this:

$(document).ready({function() {
    $('#Schedule').getSced = getScheduleList();
    ...

Comments

0

even if it works for you, try to use this instead

'<li><h4>' + item.Event_Date +'</h4></li>' 

the not closed tag can be a problem.

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.