Getting a blank response when calling CouchDB over ajax

I am new to CouchDB, so please bear with me.

I have a CouchDB instance running on a virtual machine. I can access it simply through the browser via futon or directly:

http://192.168.62.128:5984/articles/hot_dog 

Calling this URL in the browser returns the correct JSON. But, when I try to name this exact url via ajax, I get nothing:

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

A look at the response header with Firebug shows me that the HTTP response was 200 and the content-length was the correct size. Even Etag matches what's in CouchDB. But the answer itself is empty!

URL is absolutely right; I checked the triple and copied / pasted it directly (and, besides, I wouldn’t give a 200 answer if I hadn’t). I am using jQuery 1.4.2 and CouchDB 0.8

What's happening?

+4
source share
4 answers

It sounds very strong, as if you're trying to make an AJAX cross-domain request that the browser rejects. To get around this, you can use JSONP as the answer above, but this will limit you to GET requests; You will not be able to add, modify or delete entries.

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

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

+2
source

Try adding callback=? to a URL like this. This will launch jQuery to issue a jsonp request.

 var ajaxUrl = 'http://192.168.62.128:5984/articles/hot_dog?callback=?'; 

If this does not fix, you should add the json output example that this url gives in the browser.

+5
source

As you try to get data from another web server as your html file arrives, you need to execute a JSONP request. First of all, in the latest version of CouchDB, you need to include JSONP requests in the configuration file (.ini). (It is disabled by default with CouchDB 1.0). In the [httpd] section you need to add

allow_jsonp = true

After that, you can create JSONP requests on your CouchDB.

In jQuery do you need to add? callback =? to the url to start the JSONP request.

The happy Cross-Origin resource sharing everyone.

+5
source

firstly this is a json question and you noted jquery ...

if you need jquery function then ... look load load ().

.

$ ('# selector') load (ajaxURL); notifications ($ ('# selector'). HTML ())

-2
source

Source: https://habr.com/ru/post/1304942/


All Articles