Skip to content

Instantly share code, notes, and snippets.

@gosukiwi
Created July 24, 2012 15:59
Show Gist options
  • Save gosukiwi/3170854 to your computer and use it in GitHub Desktop.
Save gosukiwi/3170854 to your computer and use it in GitHub Desktop.
(function () {
"use strict";
var Todos = [];
var Todo = function () {
this.title = null;
this.isDone = false;
};
$(document).ready(function () {
$('#btn-add').click(function () {
var title = $('#todo-title');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TodoManager.asmx/AddTodo",
dataType: "json",
data: '{ "title": "' + title.val() + '", "isDone": false }',
success: function (data) {
var todo = new Todo();
todo.title = data.d.title;
todo.isDone = data.d.isDone;
Todos.push(todo);
$('#todo-list').append('<li>' + todo.title + '</li>');
$('#total-todos').html(Todos.length);
title.val('').focus();
}
});
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment