You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by "Wu,Shaolong" <SW...@mdanderson.org> on 2010/03/02 20:55:44 UTC

Any Javascript example for conenction to the couchDB server

Hi,

I am really at the beginning. I would like to use the couch.js at the client site. Couch.js defines the CouchDB. But I did not find anything that specify the host information. How do you specify the server host information?


Here is a simple thing I want to test first:

I want to use the couch.js. First connect to the server, then create a database, then insert some doc.

<script type="text/javascript">

        function testCouchDB()
        {

            CouchDB.host = "127.0.0.1:5984"; // I know this is wrong, but how do I do that?

            var db = new CouchDB("test", {"X-Couch-Full-Commit":"false"});


            db.createDb();

            var nc = {_id:"NC", cities:["Charlotte", "Raleigh"]};
            var ma = {_id:"MA", cities:["Boston", "Lowell", "Worcester", "Cambridge", "Springfield"]};
            var fl = {_id:"FL", cities:["Miami", "Tampa", "Orlando", "Springfield"]};

            db.save(nc);
            db.save(ma);
            db.save(fl);

        }
        </script>






Shaolong Wu

System Analyst III
BCB Programming Service
Division of Quantitative Sciences
University of Texas MD Anderson Cancer Center
713-792-2604




Re: Any Javascript example for conenction to the couchDB server

Posted by J Chris Anderson <jc...@gmail.com>.
On Mar 2, 2010, at 11:55 AM, Wu,Shaolong wrote:

> Hi,
> 
> I am really at the beginning. I would like to use the couch.js at the client site. Couch.js defines the CouchDB. But I did not find anything that specify the host information. How do you specify the server host information?
> 

The most basic answer is that for JavaScript clients, the host will usually be the same as the host the HTML file was served from. The same-origin rules require it to be this way.

See the source code of Futon for examples of using jquery.couch.js (better than couch.js for most purposes).

There are lots of examples of using CouchDB from the browser, but the Futon source code is the easiest to get. See: 

http://github.com/apache/couchdb/tree/trunk/share/www

Hope this helps,
Chris

> 
> Here is a simple thing I want to test first:
> 
> I want to use the couch.js. First connect to the server, then create a database, then insert some doc.
> 
> <script type="text/javascript">
> 
>        function testCouchDB()
>        {
> 
>            CouchDB.host = "127.0.0.1:5984"; // I know this is wrong, but how do I do that?
> 
>            var db = new CouchDB("test", {"X-Couch-Full-Commit":"false"});
> 
> 
>            db.createDb();
> 
>            var nc = {_id:"NC", cities:["Charlotte", "Raleigh"]};
>            var ma = {_id:"MA", cities:["Boston", "Lowell", "Worcester", "Cambridge", "Springfield"]};
>            var fl = {_id:"FL", cities:["Miami", "Tampa", "Orlando", "Springfield"]};
> 
>            db.save(nc);
>            db.save(ma);
>            db.save(fl);
> 
>        }
>        </script>
> 
> 
> 
> 
> 
> 
> Shaolong Wu
> 
> System Analyst III
> BCB Programming Service
> Division of Quantitative Sciences
> University of Texas MD Anderson Cancer Center
> 713-792-2604
> 
> 
>