Connection AJAX, CouchDB and JavaScript - Stack Overflow

i've got a little problem with AJAX, CouchDB and JavaScript.I can open the following URL from Couc

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

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.

Can you help me?

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

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.

Can you help me?

Share Improve this question edited Dec 28, 2011 at 20:43 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Aug 2, 2010 at 9:59 ChrisChris 511 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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)

But there is a kind of a mon 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

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./getjson?callback=parseResponse">
</script>

But for details refer to the article linked above.

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 doesn't support cross domain scripting. all calls need to be to a URL with the same domain as the one of the current document. a good solution would be to build a proxy service on the server side, that will take the local request, make an HTTP call to the couchDB server, and return it's response.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742329770a4423480.html

相关推荐

  • Connection AJAX, CouchDB and JavaScript - Stack Overflow

    i've got a little problem with AJAX, CouchDB and JavaScript.I can open the following URL from Couc

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信