连接AJAX,CouchDB的和JavaScript [英] Connection AJAX, CouchDB and JavaScript

查看:104
本文介绍了连接AJAX,CouchDB的和JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,AJAX,CouchDB的和JavaScript。

i've got a little problem with AJAX, CouchDB and JavaScript.

我可以在我的浏览器中打开从CouchDB的以下网址: http://192.168.1.58:5984/ MYDB /名称

I can open the following URL from CouchDB in my browser: http://192.168.1.58:5984/mydb/name

new Ajax.Request('http://192.168.1.58:5984/mydb/namee', {
  method: 'POST',
  onComplete: function(transport) {
   alert(transport.responseText);
  }
 });

我总是空的警告。

I always get empty alert.

您能帮我吗?

推荐答案

这里的问题是,您的浏览器不允许你做一个查询的其他Web服务器上而不是之一,你的脚本来源于上。 (谷歌为:同源策略)

The problem here is, that your browser doesn't allow you to make a query on an other web server than the one where you're script originates. (Google for: Same Origin Policy)

但有一种常见的技术,它是一种解决方法的使用情况。这就是所谓的 JSONP 。由于1.0版本,你必须在CouchDB中先激活这个功能。在您的CouchDB配置文件的部分[httpd的(.INI),你必须添加一个

But there is a kind of a common technique which is a workaround for this use case. It's called JSONP. Since version 1.0 you have to activate this functionality first in CouchDB. In the section [httpd] of your CouchDB configuration file (.ini) you have to add an

allow_jsonp = TRUE

allow_jsonp = true

在这样做了,你可以在你的CouchDB产生JSONP查询。基本上,增加动态线路是这样的:

After this is done you can produce JSONP queries on your CouchDB. Basically adding dynamically lines like this:

<script type="text/javascript" 
     src="http://server2.example.com/getjson?callback=parseResponse">
</script>

但对于详情,请参阅上面的文章链接。

But for details refer to the article linked above.

无论如何,我建议对事物的使用框架为jQuery的,DojoToolKit,等的JavaScript端。在jQuery的如它足以增加?回调=?在URL的结尾。

Anyway I propose on the JavaScript side of things to use a Framework as jQuery, DojoToolKit, ect. In jQuery e.g. it is enough to add "?callback=?" at the end of the URL.

这篇关于连接AJAX,CouchDB的和JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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