Flotolk
Flotolk

Reputation: 332

jQuery not posting JSON

I am trying to use the CouchDB API to query a specific view. Here is what I am using:

  $.post(targetURL,
    {
      "keys": ["Query Value"]
    },
    function (data, status) {
      console.log("Data");
      console.log(data);
    }).catch((err) => {
      console.log(err);
    });

However, when running this I get this 415 code:

"bad_content_type", reason: "Content-Type must be application/json"

What am I doing wrong?

Upvotes: 1

Views: 51

Answers (1)

Martin M
Martin M

Reputation: 465

I would try something like:

var dataModel = {
  keys: ["Query Value"]
};
$.ajax({
  url: 'http://xxxxxxxxx',
  type: 'POST',
  content: 'application/json',
  dataType: 'json',
  data: JSON.stringify(dataModel),
  success: function(data, status, xhr){

  }
});

Upvotes: 3

Related Questions