问题描述
我找到了答案这里是下面的问题.
我需要在apache中设置反向代理,这大约需要2分钟,方法是将以下行添加到我的病毒宿主中;
ProxyPass/couchdb/ http://dojo:5984/
由于具有相同的原始策略,因此无法跨端口发布数据.我知道这适用于域,但不适用于不同的端口,因此您设置了反向代理.
I found the answer here to the question below.
I needed to setup a reverse proxy in apache which took about 2 minutes by adding the following line to my virual host;
ProxyPass /couchdb/ http://dojo:5984/
Because of the same origin policy you can't post data across ports. I knew this applied to domains but not different ports so you set up a reverse proxy.
我想知道如何使用JavaScript或jQuery将数据发布到benchDB.
我遵循了这个 tut 并创建了一个数据库,我能够使用curl发布和获取数据,一切正常.下面有一些我使用的curl示例.
我也可以使用jQuery获取数据,但是我不知道如何发布到CouchDB
I would like to know how I can POST data to couchDB using JavaScript or jQuery.
I followed this tut and created a database and I'm able to post and get data using curl and it all works fine. There are curl examples below that I used.
I'm also able to get data using jQuery but I don't know how to POST to CouchDB
curl -X GET http://127.0.0.1:5984/mycouchshop/_all_docs .
curl -X POST http://127.0.0.1:5984/mycouchshop/ -d @person. json -H内容类型:应用程序/json"
curl -X GET http://127.0.0.1:5984/mycouchshop/_all_docs.
curl -X POST http://127.0.0.1:5984/mycouchshop/ -d @person.json -H "Content-Type: application/json"
我能够使用jQuery获取并显示数据.下面的代码可以正常工作.
I'm able to get and display data using jQuery. The code below works fine.
$.ajax({
url : 'http://couchdb:5984/mycouchshop/_design/peoples/_view/people',
type : 'GET',
dataType : "jsonp",
success : function(json) {}
});
但是发布数据会导致 405不允许的方法
$.ajax({
url : 'http://couchdb:5984/mycouchshop/',
data : {"forename": "Bob", "surname": "McHamster", "type": "person"},
contentType : "application/json",
type : 'POST',
dataType : "json",
success : function(resp) {}
});
推荐答案
相同起源的安全策略
我不是CouchApp专家,但遇到了同样的问题.问题是您正在跨域限制,您的应用程序从一个端口提供服务,而ouchdb在另一个端口上访问.来自 couchapp.org :
因此,最简单的CouchApp只是一个HTML文件, 直接从CouchDB使用Ajax从 CouchDB.
So, the simplest possible CouchApp is just an HTML file, served directly from CouchDB, that uses Ajax to load and save data from the CouchDB.
使用couchapp
似乎所有应用程序文件都需要使用ouchapp(http://couchapp.org/page/index)推"到该长沙发服务器.我使用的是Mac,因此我使用了独立可执行文件. 有
了解了沙发应用程序的工作原理后,您可以使用本教程
When you understand how couchapp works, you can use this tutorial
我正在尝试找出它们...如果您发现任何不错的东西,请分享!祝你好运!
I am trying to figure them out... if you find anything good, please share! Good luck!
:我刚刚发现本教程
I just found this tutorial
这篇关于如何使用JavaScript/jQuery将新数据发布到CouchDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!