couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <d...@muse.net.nz>
Subject Re: get view json into javascript variable
Date Sun, 15 Aug 2010 06:44:00 GMT
On 10 August 2010 19:06,  <whimsica@aol.com> wrote:
>
>  How can I get a view into a javascript variable on an html page?
> I have a web based json viewer but I need to get the view json out
> of couchdb and into a javascript variable on the webpage to make it work.
>
> Thanks,
>
> Dan
>
> I can't figure out how to do this from the documentation or hours of browsing around
and reading the two couchdb books.

Well I am a crap javascript programmer (think duplo building blocks)
but this works for me - is this what you were missing?

	<script type="text/javascript">
		$.getJSON("/mydb/dave@example.org", function(json){
		  alert(json.name + " lives in " + json.location + " and you can fax
to " + json.fax);
		});
	</script>

& the doc on the couch:

{
    "_id": "dave@example.org",
    "type": "contact",
    "site": "NZL.Wellington",
    "phone": "+64 4 9727208",
    "fax": "+64 4 9727123",
    "name": "Dave Cottlehuber"
}

It should be the same for a view, your URL will be different.

cheers
Dave

Mime
View raw message