Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I POST new data to CouchDB using JavaScript/jQuery
    primarykey
    data
    text
    <p>I found the answer <a href="https://stackoverflow.com/questions/2099728/how-do-i-send-an-ajax-request-on-a-different-port-with-jquery">here</a> to the question below.<br><br> I needed to setup a reverse proxy in apache which took about 2 minutes by adding the following line to my virual host; <br> ProxyPass /couchdb/ <a href="http://dojo:5984/" rel="nofollow noreferrer">http://dojo:5984/</a><br> Because of the same origin policy you can't post data across ports. I knew this applied to domains but not different ports so you set up a reverse proxy.</p> <hr> <p>I would like to know how I can POST data to couchDB using JavaScript or jQuery.<br><br> I followed this <a href="http://net.tutsplus.com/tutorials/getting-started-with-couchdb/" rel="nofollow noreferrer">tut</a> and created a database and I'm able to post and get data using curl and it all works fine. There are curl examples below that I used. <br><br> I'm also able to get data using jQuery but I don't know how to POST to CouchDB</p> <p>curl -X GET <a href="http://127.0.0.1:5984/mycouchshop/_all_docs" rel="nofollow noreferrer">http://127.0.0.1:5984/mycouchshop/_all_docs</a>. <br> curl -X POST <a href="http://127.0.0.1:5984/mycouchshop/" rel="nofollow noreferrer">http://127.0.0.1:5984/mycouchshop/</a> -d @person.json -H "Content-Type: application/json"</p> <p>I'm able to get and display data using jQuery. The code below works fine.</p> <pre><code> $.ajax({ url : 'http://couchdb:5984/mycouchshop/_design/peoples/_view/people', type : 'GET', dataType : "jsonp", success : function(json) {} }); </code></pre> <p>But posting data results in a <em>405 Method Not Allowed</em></p> <pre><code> $.ajax({ url : 'http://couchdb:5984/mycouchshop/', data : {"forename": "Bob", "surname": "McHamster", "type": "person"}, contentType : "application/json", type : 'POST', dataType : "json", success : function(resp) {} }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload