Permalink
Browse files

Initial

  • Loading branch information...
pifantastic committed Jan 28, 2011
0 parents commit 7cee07bd1c11b04d690fdafccec5edb9f98a160b
Showing with 66 additions and 0 deletions.
  1. +49 −0 index.html
  2. +17 −0 server.php
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>My todo list</title>
+</head>
+<body>
+ <h1>My todo list</h1>
+ <form>
+ <input type="text" id="item" />
+ <input type="submit" value="Save" id="save" />
+ </form>
+ <ul id="list"></ul>
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
+ <script>
+ $(document).ready(function() {
+ $.getJSON("http://localhost/server.php", function(data) {
+ for (var x = 0; x < data.length; x++) {
+ $('#list').append('<li>' + data[x] + '</li>');
+ }
+ });
+
+ $('form').submit(function(e) {
+ var item = $('#item').val();
+ $('#list').append('<li>' + item + '</li>');
+ $('#item').val('');
+ save();
+ return false;
+ });
+
+ $('#list li').live('dblclick', function() {
+ $(this).remove();
+ save();
+ });
+
+ function save() {
+ var items = [];
+ $('#list li').each(function() {
+ items.push($(this).text());
+ });
+
+ $.ajax({
+ url: "http://localhost/server.php",
+ data: { list: items }
+ });
+ }
+ });
+ </script>
+</body>
+</html>
@@ -0,0 +1,17 @@
+<?php
+
+session_start();
+
+// Initialize session if empty.
+if (!isset($_SESSION['list'])) {
+ $_SESSION['list'] = array();
+}
+
+// Update list.
+if (isset($_REQUEST['list'])) {
+ $_SESSION['list'] = $_REQUEST['list'];
+}
+
+// Return list as JSON.
+header('Content-Type: application/json');
+die(json_encode($_SESSION['list']));

0 comments on commit 7cee07b

Please sign in to comment.