assets/js/lib/jquery.couch.js
function(doc, options) {
          options = options || {};
          var db = this;
          var beforeSend = fullCommit(options);
          if (doc._id === undefined) {
            var method = "POST";
            var uri = this.uri;
          } else {
            var method = "PUT";
            var uri = this.uri + encodeDocId(doc._id);
          }
          var versioned = maybeApplyVersion(doc);
          $.ajax({
            type: method, url: uri + encodeOptions(options),
            contentType: "application/json",
            dataType: "json", data: toJSON(doc),
            beforeSend : beforeSend,
            complete: function(req) {
              var resp = $.parseJSON(req.responseText);
              if (req.status == 200 || req.status == 201 || req.status == 202) {
                doc._id = resp.id;
                doc._rev = resp.rev;
                if (versioned) {
                  db.openDoc(doc._id, {
                    attachPrevRev : true,
                    success : function(d) {
                      doc._attachments = d._attachments;
                      if (options.success) options.success(resp);
                    }
                  });
                } else {
                  if (options.success) options.success(resp);
                }
              } else if (options.error) {
                options.error(req.status, resp.error, resp.reason);
              } else {
                throw "The document could not be saved: " + resp.reason;
              }
            }
          });
        }
function(doc, options) {
          options = options || {};
          var db = this;
          var beforeSend = fullCommit(options);
          if (doc._id === undefined) {
            var method = "POST";
            var uri = this.uri;
          } else {
            var method = "PUT";
            var uri = this.uri + encodeDocId(doc._id);
          }
          var versioned = maybeApplyVersion(doc);
          $.ajax({
            type: method, url: uri + encodeOptions(options),
            contentType: "application/json",
            dataType: "json", data: toJSON(doc),
            beforeSend : beforeSend,
            complete: function(req) {
              var resp = $.parseJSON(req.responseText);
              if (req.status == 200 || req.status == 201 || req.status == 202) {
                doc._id = resp.id;
                doc._rev = resp.rev;
                if (versioned) {
                  db.openDoc(doc._id, {
                    attachPrevRev : true,
                    success : function(d) {
                      doc._attachments = d._attachments;
                      if (options.success) options.success(resp);
                    }
                  });
                } else {
                  if (options.success) options.success(resp);
                }
              } else if (options.error) {
                options.error(req.status, resp.error, resp.reason);
              } else {
                throw "The document could not be saved: " + resp.reason;
              }
            }
          });
        }
function ( doc , options ) { options = options || { } ; var db = this ; var beforeSend = fullCommit ( options ) ; if ( doc . _id === undefined ) { var method = "POST" ; var uri = this . uri ; } else { var method = "PUT" ; var uri = this . uri + encodeDocId ( doc . _id ) ; } var versioned = maybeApplyVersion ( doc ) ; $ . ajax ( { type : method , url : uri + encodeOptions ( options ) , contentType : "application/json" , dataType : "json" , data : toJSON ( doc ) , beforeSend : beforeSend , complete : function ( req ) { var resp = $ . parseJSON ( req . responseText ) ; if ( req . status == 200 || req . status == 201 || req . status == 202 ) { doc . _id = resp . id ; doc . _rev = resp . rev ; if ( versioned ) { db . openDoc ( doc . _id , { attachPrevRev : true , success : function ( d ) { doc . _attachments = d . _attachments ; if ( options . success ) options . success ( resp ) ; } } ) ; } else { if ( options . success ) options . success ( resp ) ; } } else if ( options . error ) { options . error ( req . status , resp . error , resp . reason ) ; } else { throw "The document could not be saved: " + resp . reason ; } } } ) ; }
Create a new document in the specified database, using the supplied
JSON document structure. If the JSON structure includes the _id
field, then the document will be created with the specified document
ID. If the _id field is not specified, a new unique ID will be
generated.
@see <a href="http://techzone.couchbase.com/sites/default/files/
uploads/all/documentation/couchbase-api-dbdoc.html#couchbase-api-
dbdoc_db_post">docs for GET /db/doc</a>
@param {String} doc document to save
@param {ajaxSettings} options <a href="http://api.jquery.com/
jQuery.ajax/#jQuery-ajax-settings">jQuery ajax settings</a>
Create a new document in the specified database using the supplied JSON document structure . If the JSON structure includes the _id field then the document will be created with the specified document ID . If the _id field is not specified a new unique ID will be generated .