No title Revision 613961333362 (Mon Apr 18 2011 at 00:37) - Diff Link to this snippet: https://friendpaste.com/1Am5LLeuTrbDugOyW9jf5s Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<!DOCTYPE html><html> <head><title>Tiny CouchApp</title></head> <body> <h1>Tiny CouchApp</h1> <form id="new_message"> <label for="message">Message:</label> <input type="text" name="message" value=""> <p><input type="submit" value="Save →"></p> </form> <ul id="messages"></ul> </body> <script src="/_utils/script/jquery.js"></script> <script src="/_utils/script/jquery.couch.js"></script> <script> $(function() { var db = $.couch.db("mydb"); $("#new_message").submit(function() { // save the message to couchdb var doc = {}, input = $("input[name=message]", this); doc.message = input.val(); doc.created_at = new Date(); console.log(doc); db.saveDoc(doc, { success : function(r) { input.val(""); } }); return false; }); function redrawMessages() { db.view("messages/by_time", { descending : true, success : function(resp) { var list = $("#messages"); list.empty(); resp.rows.forEach(function(row) { list.append('<li>'+row.value+'</li>'); }); } }) }; redrawMessages(); var changeHandler = db.changes(); changeHandler.onChange(redrawMessages); }); </script></html>