Friday, June 01, 2012

415 unsupported media type couchdb jquery

Hate it when I repeat a mistake. Worse when I repeat it.

Adding a new record to couchdb requires a POST and jQuery supports that verb. So I did the simple
    $.post(toc.dbUrl+'techtocs', data, function(data) {
        alert("Data Loaded: " + data);

But this got me the "415 unsupported media type" error. I was sending application/json type but I still got the error. So I finally looked up my old code and did this:
        type: 'POST',
        dataType: 'json',
 contentType: "application/json",
 data: JSON.stringify(data),
 url: toc.dbUrl+'techtocs',
 success: function(sdata){
     //stuff here+ 

Glad to get it working on this project where techtocs is the database name.

1 comment:

Matt Steele said...

Hey, you deserve a lot of credit for this....been tearing my hair our. Thanks a million.