I have tried to create a _design document when I was studying at REST API documentation. But my ajax function response status: 400. It’s got five different meaning. I guess in my case its mean is “Invalid JSON” or “Invalid parameter in HTTP query or JSON body”
400 Bad data encoding
400 bad_request
400 Invalid attachment
400 Invalid database/document/revision ID
400 Invalid JSON
400 Invalid parameter in HTTP query or JSON body
I’ve tried create a view simplicity. I couldn’t find any reasons.
What’s wrong with my codes?
$("#create").on("tap", function() {
var view = {
"language": "javascript",
"views": {
"user": {
"map": "function(doc) {if (doc.username) {emit(doc)}}"
}
}
}
console.log(view);
$.ajax({
url: "http://localhost:5984/user/_design/user",
type: 'PUT',
data: view,
success: function (data, textStatus, xhr) {
console.log(xhr);
},
error: function (xhr, statusText, error) {
console.log(xhr);
}
});
});
ps: The port number - that was used by me - is 5984. But the port is 59840 at the documentation. I get “status:0” when I use port 59840.