tags:

views:

86

answers:

1

I can't access my CouchDB server (CouchDBX) using a jQuery AJAX call.

I am able to access my demo database at localhost:5984/helloworld/_all_docs through browsers (tested with FireFox, Chrome and Safari). But when I do a simple AJAX call using jQuery I get no data returned.

The requests completes with code 200.


Here's what my AJAX call looks like:

$(function ()
{
    $.ajax(
    {
        cache: false,
        dataType: "json",
        error: function (xmlHttpRequest, textStatus, errorThrown)
        {
            console.log("error", xmlHttpRequest, textStatus, errorThrown);
        },
        global: false,
        success: function (data, textStatus, xmlHttpRequest)
        {
            console.log("success", data, textStatus, xmlHttpRequest);
        },
        timeout: 3000,
        url: "http://localhost:5984/helloworld/_all_docs"
    });
});

What am I doing wrong?


Update

Screenshots of FireBug console:

http://grab.by/6fkS

http://grab.by/6fkX

http://grab.by/6fkY

A: 

I think your browser is blocking the data.

http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin

http://www.w3.org/TR/cors/

duluthian
Yep. Just ran your code in Chrome, which threw an error: XMLHttpRequest cannot load http://127.0.0.1:5984/db/_all_docs?_=1283713669140. Origin null is not allowed by Access-Control-Allow-Origin.
duluthian
So I need to get a HTTP server running, and run my pages there instead of just opening them from disk? Would that solve my same-origin-policy issues?
roosteronacid
Upload them as document attachments and hit them from the browser that way. (This is how CouchApps do it.) That way you're actually serving pages and data from the same Origin.
duluthian