关于用户空间中CouchJS的简单示例(例如,带有浏览器)? [英] Simple example about CouchJS in userspace for example with Browser?

查看:70
本文介绍了关于用户空间中CouchJS的简单示例(例如,带有浏览器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CouchJs :CouchDB的JavaScript解释器

CouchJs : the JavaScript interpreter for CouchDB

CouchDB :一个NonSQL数据库,您可以在其中使用JS之类的功能在用户空间中执行大多数操作,因为在数据库级执行操作通常会很昂贵

CouchDB : a NonSQL db where you execute most things in user-space with things such as JS because things tend to be expensive to execute on the database-level

完整性:在信息安全中,完整性意味着不能不可检测地修改数据.在此处.

Integrity : In information security, integrity means that data cannot be modified undetectably. More here.

CouchJS网站没有内部搜索,并且在搜索或多或少令人困惑的博客文章之后,我迷路了.在哪里可以找到如下所示的一些简单示例(不仅是curl/telnet)?

The CouchJS website has no internal search, and after googling more-or-less confusing blog articles, I'm getting lost. Where can I find some simple examples (not just curls/telnets) like below around?

<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>

也许对其他新手有用

  1. CouchDB真实示例,其中引用了免费书籍等等

  1. CouchDB a real world example, thread with references to free books etc

CouchJS的源代码这里.

Source code of CouchJS here.

https://stackoverflow.com/questions/11077093/what-are-ajax-options-in-couchjs-explain-this-odd-null-error-with-couchjs

推荐答案

以弗洛里安的答案为基础-因为当我指出某些错误此处和示例在这里接受字符串,而不是对象-我编辑了他的答案以添加XMLHttpRequest -manual进行进一步调查,但是由于某些原因,有人取消了该编辑.因此,我自己做出的回答最多,但修复得最多,但仍然使我仍在尝试解决的DOM 11感到恼怒.

Building on top of the Florian's answer -- because he removed his answer when I pointed out some errors here, please, skimread his answer in history. He suggested the article about document update handlers here and the example here. There are two problems at least, the XMLHttpRequest here takes a string, not object -- I edited his answer to add the XMLHttpRequest -manual for further investigation but for some reason someone cancelled the edit. So I am making my own answer having the most fixes but still irritating DOM 11 that I am still trying to solve.

// 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);

待办事项

  • 现在XMLHttpRequest出现一个错误不处理嵌套对象" ,而是字符串,因此我们需要更复杂的命令或数组 XMLHttpRequest.我感谢C. * rk在此方面的帮助.
  • 可能与test.js有关,正在调查错误:"XMLHttpRequest cannot load %3127.0.0.1:5984/test/559c327683fe0acb96aff72bd174c258. Cross origin requests are only supported for HTTP. Error: NETWORK_ERR: XMLHttpRequest Exception 101"
  • Now there is one error XMLHttpRequest "does not handle nested objects" but string so we need either more complex command or arrays with XMLHttpRequest. I thank C.*rk for helping me with this.
  • Probably RELATING TO test.js, under investigation the 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"

相关难题

  1. [已解决] 解释DOM使用JSON -headers初始化XMLHttpRequest时出现11个错误

这篇关于关于用户空间中CouchJS的简单示例(例如,带有浏览器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆