Skip to content

Instantly share code, notes, and snippets.

@holtbp
Created March 27, 2012 23:28
Show Gist options
  • Save holtbp/2221456 to your computer and use it in GitHub Desktop.
Save holtbp/2221456 to your computer and use it in GitHub Desktop.
Output AJAX response into UL on page
//jQuery.ajax - Success, error and complete are deprecated in jQuery 1.8
function toListItem(element) {
return '<li>' + element + '</li>';
}
var first = $.ajax({
type: "GET",
url: "/items",
accepts: "text/json"
});
first.done(function(data) {
var list = $('<ul>');
$(data).each(function() {
list.append(toListItem(this.name));
if(this.extras !== null) {
list.append(toListItem(this.extras.join(", ")));
}
});
$('body').html(list);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment