I am prototyping a very simple webapp. Today I installed Couch 1.3.1 and created a database. I am trying to save a document on my local couch (localhost: 5984) with POST from the client browser also on localhost, but a different port (6789)
var dbIp = "http://localhost:5984/commute"; var data = {state:0,timestamp:"faketime"}; $.ajax({ type: 'POST', crossDomain: true, contentType: "application/json", url: dbIp, data: data, success: function(result) { console.log(result); } });
I get:
XMLHttpRequest cannot load http://localhost:5984/commute-tracker. Origin http://localhost:6789 is not allowed by Access-Control-Allow-Origin.
I changed local.ini to enable CORS as described in couchdb spec with
[httpd] enable_cors = true [cors] origins = * [cors] methods = GET, POST, PUT, DELETE
I see all these changes reflected in the configuration file in futon. I also checked the swirl database:
curl -X POST localhost:5984/commute -H "Content-Type: application/json" -d '{"tags":"sure","name":"made it"}'
Twisting works just fine, but I can't do a similar POST in the browser due to Allow Origin access control. What else am I missing, or what can I change to make this POST possible?
source share