I am using node.js with express, jade and sass for my application. I have a couchdb database and I would like to use this using AJAX. Normally, to access couchdb with AJAX you would create a document in the database and attach the html file to it, so that it is served from the same domain. However, most of the site will be generated using templates served by node.js, which means being served from a different domain to couchdb's server. How do I get round this?
Asked
Active
Viewed 992 times
1 Answers
0
You need to enable cross-domain communication in express, please check this answer: Using Express and Node, how to maintain a Session across subdomains/hostheaders
As well you might consider of using jsonp
for most browser support. In order to enable it just add this line:
app.set('jsonp callback', true);
To your app.configure
in express.
And then when you send answers use this method:
res.jsonp({ some: 'data' });
-
Many thanks. Presumably, the first solution is needed to allow posting of data? – George of all trades Jul 11 '13 at 10:19
-
The content at link, allows to have shared session as well as allows backend to response to cross-domain requests. As there is two sides that might limit your from CORS. And the additional content in answer above, is to enable jsonp, which will make IE 'happy'. – moka Jul 11 '13 at 10:25