通过Ajax调用CouchDB时得到空响应 [英] Getting an empty response when calling CouchDB over ajax

查看:167
本文介绍了通过Ajax调用CouchDB时得到空响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CouchDB的新手,所以请多多包涵.

I'm new to CouchDB, so please bear with me.

我有一个在VM上运行的CouchDB实例.我可以通过浏览器通过futon或直接在以下网址访问它:

I have an instance of CouchDB running on a VM. I can access it just fine through the browser via futon or directly at:

http://192.168.62.128:5984/articles/hot_dog

在浏览器中调用该URL将返回正确的JSON.但是,当我尝试通过ajax调用相同的URL时,却什么也没得到:

Calling that URL in a browser returns the proper JSON. But, when I try to call that exact same URL via ajax, I get nothing:

var ajaxUrl = 'http://192.168.62.128:5984/articles/hot_dog';
$.getJSON(ajaxUrl, null, function(data) { alert(data); });

使用Firebug查看响应标头后,我发现HTTP响应为200,而content-length的大小正确.甚至Etag都与CouchDB中的内容匹配.但是响应本身是 empty

Looking at the response header with Firebug shows me that the HTTP response was 200 and the content-length is the right size. Even the Etag matches with what is in CouchDB. But the response itself is empty!

URL绝对正确;我已经三重检查,并直接将其复制/粘贴(此外,如果没有,则不会给出200的响应).我正在使用jQuery 1.4.2和CouchDB 0.8

The URL is absolutely right; I've triple checked, and copy/pasted it directly (and besides it wouldn't give a 200 response if it weren't). I'm using jQuery 1.4.2, and CouchDB 0.8

这是怎么回事?

推荐答案

听起来很像您正在尝试提出跨域AJAX请求,但浏览器将拒绝该请求.为了解决这个问题,您可以像上面的答案一样使用JSONP,但这将限制您进行GET请求.您将无法添加,修改或删除记录.

Sounds very strongly like you're trying to make a cross-domain AJAX request, which the browser will reject. To get around this, you can use JSONP like the answer above, but this will restrict you to GET requests; you won't be able to add, modify, or delete records.

如果您尝试使用CouchDB进行跨域AJAX调用,建议您检查一下该库:

If you are trying to do cross-domain AJAX calls with CouchDB, I recommend checking out this library:

http://github.com/benvinegar/couchdb-xd

这篇关于通过Ajax调用CouchDB时得到空响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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