Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7076077

Browse files
committed
add no todos handling and text
1 parent cbe1e24 commit 7076077

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

week3/index.html

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ <h4>Add To Do</h4>
5353

5454
function showTodos(data, status) {
5555
$("#todo_list").empty();
56-
$.each(data, function (i, val) {
57-
$("#todo_list").append(i + " " + val + " <span id='todo" + i + "'>Remove<br>");
58-
$("#todo" + i).css(buttonCSS);
59-
$("#todo" + i).click(function(){
60-
$.ajax({
61-
url: "http://localhost:8080/todos/" + i,
62-
method: "DELETE",
63-
success: showTodos
64-
})
65-
});
66-
});
56+
if ($.isEmptyObject(data)) {
57+
$("#todo_list").append("<h4>You have nothing to do!</h4>");
58+
} else {
59+
$.each(data, function (i, val) {
60+
$("#todo_list").append(i + " " + val + " <span id='todo" + i + "'>Remove<br>");
61+
$("#todo" + i).css(buttonCSS);
62+
$("#todo" + i).click(function(){
63+
$.ajax({
64+
url: "http://localhost:8080/todos/" + i,
65+
method: "DELETE",
66+
success: showTodos
67+
})
68+
});
69+
});
70+
}
6771
}
6872
});
6973
</script>

0 commit comments

Comments
 (0)