Reputation: 11
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!
Upvotes: 1
Views: 190
Reputation: 1416
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.
Upvotes: 0
Reputation: 1868
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();
...
Upvotes: 0
Reputation: 324640
schedules = data.items
- data
does not contain a property named items
. You probably want schedules = data.schedules
instead.
Upvotes: 2