// Ajax with jQuery
// We will be using this service to fetch data
// This server is friendly enough to be CORS:*
// http://jsonplaceholder.typicode.com/
// if we have trouble with that, we can do this on
// local servers fetching up static .json data
//
// Part 1
// Make a JSON request to
// http://jsonplaceholder.typicode.com/todos
// Load the data from here and build a ul/li of TODO items
// Each todo items should display at least its title
// Hint: filter by a userId to limit the data, ?userId=5
var prom = $.getJSON('http://jsonplaceholder.typicode.com/todos?userId=5');
// display a loading thingy...
prom.done(function(response) {
// console.log(response);
// hide loading thingy...
var $containerEl = $(".container");
var $newUl = $("<ul></ul>");
for (var i=0; i<response.length; i++) {
var $newLi = $("<li><input type='checkbox' value='1' /></li>");
if (response[i].completed) {
$newLi.find("input").attr("checked", "true");
}
$newLi.attr("data-id", response[i].id);
$newLi.append(" " + response[i].title);
$newUl.append($newLi);
}
$containerEl.append($newUl);
});
prom.always(function() {
// hide my loading thingy...
});
prom.fail(function(){
// display or render a small element in the page
// that indicates an error to the user
});
function displayUser() {
var $containerEl = $(".container");
var $modal = $("<div id='modal'></div>");
$modal.hide();
$modal.html("User is...");
$containerEl.append($modal);
$modal.fadeIn();
}
// Part 2
// Completion checkbox
//
// Include a checkbox with each todo item.
// The checkbox should be checked when the item is completed
// And unchecked when the item is not completed
$(".container").on("change", "input[type='checkbox']", function(e) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.