Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform an Ajax request to CouchDB (http://<usename>.couchone.com/)

I'm trying to create a simple AJAX (via jQuery) request to http://yourusername.couchone.com/ (alsmost the same as if I had installed couchdb on localhost)

If I go to http://**yourusername**.couchone.com/ via Browser I'll get: {"couchdb":"Welcome","version":"1.0.1"} So, it looks like a serialized JSON.

So I wrote a JS Code:

$(function() {
        $.getJSON('http://www.********.couchone.com/', function(data) {
                console.log(data.couchdb);
                console.log(data.version);

            });
    });

But the code doesn't work. FireBug's console shows that the GET request has no response (the whole line is in red) Everything I can see is a Request-Header and Response-Header, but NO DATA (as response)

Request-Header :

Host :  www.*******.couchone.com
User-Agent :    Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 FirePHP/0.4
Accept :    application/json, text/javascript, */*
Accept-Language :   de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding :   gzip,deflate
Accept-Charset :    ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive :    115
Connection :    keep-alive
Origin :    null

Response-Header :

Server :    CouchDB/1.0.1 (Erlang OTP/R13B)
Date :  Sun, 26 Sep 2010 12:45:47 GMT
Content-Type :  application/json
Content-Length :  40
Cache-Control :  must-revalidate

Ideas? Suggestions?

P.S. Sorry for bad English

like image 683
V-Light Avatar asked Dec 08 '22 01:12

V-Light


1 Answers

I'd say that MightyE's totally right, up to the postscript -- CouchOne does support JSONP. Go to http://YOURSITE.couchone.com/_utils/config.html and change allow_jsonp in the httpd section to true. After that,

$.ajax({
   url: 'http://yoursite.couchone.com/',
   type: 'get',
   dataType: 'jsonp',
   success: function(data) {
      alert(data.couchdb);
      alert(data.version);
   }
});

will work.

like image 144
Ian Avatar answered Jan 04 '23 23:01

Ian