I’m trying to connect to my CouchDB on Cloudant using jQuery and jQuery.couch.sj
However, I can’t even get the most basic info about my database. For example the following code prints nothing to the console.
Code
<script>
$.couch.urlPrefix ="https://acharya.cloudant.com";
$.couch.info({
success: function(data) {
console.log(data);
}
});
</script>
I’ve looked at the online documentation but to no avail.
If I type
var db= $.couch.db("toxtweet");
console.debug(db);
to see something about one of my CouchDB’s, I get:
Object { name="toxtweet",uri="https://acharya.cloudant.com/toxtweet/", compact=function(),
more...}
And that is the correct URI. So, how would I, for example, get the number of documents in the “toxtweet” database? Trying the example doesn’t work.
Update
If I view the page in Chrome instead of Firefox I see the following error.
XMLHttpRequest cannot load https://acharya.cloudant.com/. Origin http://tox.sinaiem.org is not
allowed by Access-Control-Allow-Origin.
I thought that Cloudant was a CouchApp that bypassed the same-origin policy.
I haven’t used jquery to access Cloudant, but I would expect you to have to log in somewhere first unless you have somehow made your database public.
Have you checked in Chrome or Firefox what https requests and responses jquery.couch is sending and receiving?
To get the number of documents, you would typically have a view with a reduce method like this:
see here for more info What is the CouchDB equivalent of the SQL COUNT(*) aggregate function?
I would recommend you use Futon when trying out examples before doing an equivalent request in jquery.couch
Update
Have you tried JSONP to get around cross domain issue?
see here: http://support.cloudant.com/customer/portal/articles/359321-how-do-i-read-and-write-to-my-cloudant-database-from-the-browser-