A simple example about CouchJS in user space, such as with a browser?

Definitions

CouchJs : JavaScript interpreter for CouchDB

     

CouchDB : NonSQL db, where you do most of the things in user space with things like JS, because at the database level it's usually expensive

     

Integrity : with information security, integrity means that data cannot be changed unnoticed. More details here .

The CouchJS website has no internal search, and after you come across more or less confusing blogs, I get lost. Where can I find some simple examples (and not just curls / telnets), for example below?

<script type="text/javascript" src="lib/jquery-1.7.2.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.8.21.custom.min.js"></script>
<script src="http://127.0.0.1:5984/_utils/script/jquery.couch.js"></script>
    //# 1. initilalize the db -object
    //# 2. save something to the db with the object
<script> db.test.save('hello world') </script>

Perhaps useful for other newbies.

+2
3

- , , , skimread . . , : XMLHttpRequest , - , XMLHttpRequest -manual - - . , , DOM 11, .

// By this function we solve the problem with Object, 
// changing JSON -object to string. The source is:
// https://stackoverflow.com/questions/111529/create-query-parameters-in-javascript    
function EncodeQueryData(data)
{
   var ret = [];
   for (var d in data)
      ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]));
   return ret.join("&");
}

// We use ready CouchDB -example, source:
// http://wiki.apache.org/couchdb/HTTP_Document_API#PUT
var datas = {
  "Subject":"I like Plankton",
  "Author":"Rusty",
  "PostedDate":"2006-08-15T17:30:12-04:00",
  "Tags":["plankton", "baseball", "decisions"],
  "Body":"I decided today that I don't like baseball. I like plankton."
};

// We use the default -function, please, see the O'Reilly.
// https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest
var xhr = new XMLHttpRequest();

// This may be wrong
xhr.open( 'POST', 'test.js', true );
xhr.setRequestHeader( 'Content-Type', 'application/json' );
xhr.open( 'POST', '127.0.0.1:5984/test/559c327683fe0acb96aff72bd174c258', true);

var msg = EncodeQueryData(datas);
xhr.send(msg);

TODO

  • . XMLHttpRequest " ", , XMLHttpRequest. C. * rk .
  • , test.js, err: "XMLHttpRequest cannot load %3127.0.0.1:5984/test/559c327683fe0acb96aff72bd174c258. Cross origin requests are only supported for HTTP. Error: NETWORK_ERR: XMLHttpRequest Exception 101"

+2

- CouchJS, , , :

CouchDB HTTP-, JavaScript XMLHttpRequest.

- CouchDB HttpRestApi, , .

, , , jquery, / API CouchDB Rest ajax.

, googled jquery couch , , , , - , $.couch, , , , , Rest API.

+1
+1
source

All Articles