Connection AJAX, CouchDB and JavaScript

前端 未结 2 1364
猫巷女王i
猫巷女王i 2021-01-06 00:42

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

<         


        
2条回答
  •  广开言路
    2021-01-06 01:10

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

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

    
    

    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.

提交回复
热议问题