2

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

cllpse
  • 21,396
  • 37
  • 131
  • 170
  • Can you give us the output of `console.log("success", data, textStatus, xmlHttpRequest);`? – ase Sep 05 '10 at 18:53
  • Are you certain Safari wasn't working? It is usually more permissive about cross-domain requests when hosting from the filesystem (which I assume you're doing). I just tried, and Safari returns two test documents I created (using CouchDBX). – user113716 Sep 05 '10 at 19:31

1 Answers1

0

I think your browser is blocking the data.

XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

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

Community
  • 1
  • 1
BenD
  • 821
  • 5
  • 8
  • 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. – BenD Sep 05 '10 at 19:08
  • 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? – cllpse Sep 05 '10 at 19:11
  • 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. – BenD Sep 06 '10 at 06:42