Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 11899 invoked from network); 13 Aug 2010 14:57:02 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Aug 2010 14:57:02 -0000 Received: (qmail 55210 invoked by uid 500); 13 Aug 2010 14:57:01 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 55047 invoked by uid 500); 13 Aug 2010 14:57:00 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 55038 invoked by uid 99); 13 Aug 2010 14:57:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Aug 2010 14:57:00 +0000 X-ASF-Spam-Status: No, hits=4.2 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [74.125.83.180] (HELO mail-pv0-f180.google.com) (74.125.83.180) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Aug 2010 14:56:52 +0000 Received: by pvc30 with SMTP id 30so1416688pvc.11 for ; Fri, 13 Aug 2010 07:56:31 -0700 (PDT) Received: by 10.115.107.7 with SMTP id j7mr1853082wam.107.1281711390420; Fri, 13 Aug 2010 07:56:30 -0700 (PDT) Received: from [10.0.1.2] (c-24-130-240-73.hsd1.ca.comcast.net [24.130.240.73]) by mx.google.com with ESMTPS id c24sm4734532wam.19.2010.08.13.07.56.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 13 Aug 2010 07:56:29 -0700 (PDT) Sender: J Chris Anderson From: J Chris Anderson Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: multipart/alternative; boundary=Apple-Mail-91-608995435 Subject: Re: get emit(doc.name,doc.url) to javascript variable Date: Fri, 13 Aug 2010 07:56:29 -0700 In-Reply-To: <1281401456741-5391246.post@n2.nabble.com> To: dev@couchdb.apache.org References: <1281401456741-5391246.post@n2.nabble.com> Message-Id: X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-91-608995435 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Aug 9, 2010, at 5:50 PM, whimsica wrote: >=20 > So far I'm very confused about how to get couchdb to talk to = javascript on > the web page using show or view. >=20 The challenge here is figuring out which javascript code runs in which = context. All the JS you've shown, runs on the server, not the browser. = Here are some tips about how to run JS in the browser and talk to = CouchDB: The simplest way to do this is with static HTML served as an attachment = to the browser, which makes Ajax queries to the CouchDB. This way you = don't need to fuss with a show function (which is awesome, but another = layer of indirection.) Take a look at the example code on this page (and follow the exercise): http://couchapp.org/page/what-is-couchapp#/ Where it says: $.couch.allDbs({ success : function(dbs) { dbs.forEach(function(db) { $("#databases").append('
  • '+db+'
  • '); }); } }); you might try replacing it with this, to do a view query instead = (assuming your db is called "mydb" and your view is called "myview": var db =3D $.couch.db("mydb"); db.view("myview",{ limit : 10, success : function(resp) { resp.rows.forEach(function(row) { $("#databases").append('
  • '+row.key+'
  • '); }); } }); Hope that helps. > Let's say I have a database with things like names of users and a url = that > users submit > I want to emit the results of a view in raw json form and alert it on = the > page using javascript alert() >=20 > How do I do that. >=20 > I tried putting a javascript function in a view (alert(1)) just to see = but > it gave back an error. >=20 > So far I was able to call a javascript function in a show command = below but > it's not the json from the view. >=20 > database > { > "_id": "81c76a15131be24115f53e2cafaea4e8", > "_rev": "2-5df7ac370489e818b4e72d5293069bfb", > "name": "moe", > "url": "http://www.moeshomepage.com" > } >=20 >=20 > { > "_id": "_design/yo", > "_rev": "11-3ac3428c8d47bb485b67f262248c8192", > "language": "javascript", > "views": { > "users": { > "map": "function(doc) {emit(doc.name,doc.url)}" > } > }, > "shows": { > "showall": "function(doc,req){return }" > } > } >=20 > Thank you, >=20 > Dan >=20 > --=20 > View this message in context: = http://couchdb-development.1959287.n2.nabble.com/get-emit-doc-name-doc-url= -to-javascript-variable-tp5391246p5391246.html > Sent from the CouchDB Development mailing list archive at Nabble.com. --Apple-Mail-91-608995435--