The returned object is an array
. You'll need to iterate over each element in the array.
Updated with a working demo:
$.getJSON("http://vazzak2.ci.northwestern.edu/courses/?term=4540&subject=ACCT", function(result) {
var earlyCourses = [];
$(result).each(function (index, item) {
$('#search_results').text((index+1) + " total courses");
if (item.start_time > '10:00:00') {
console.log(item);
$('#morning_results_list').append('<li>' + item.title + '</li>');
}
});
});
With the following boilerplate container:
<h2 id="search_results"></h2>
<div id="morning_results_container">
<h5>Morning Courses</h5>
<ul id="morning_results_list">
</ul>
</div>
Some notes about this example:
- The time check here is horribly naive and is reverting to an alphabetical comparison rather than an actual date/time check.
- Inserting multiple
li
in this fashion is bad for UI performance, all updates to the DOM should be batched to a single update. The example of per iteration insertion will work as long as the number of results is small (less than several hundred).
JSFIDDLE EXAMPLE: http://jsfiddle.net/h2a3t/