I am using this HTTP POST Request code to send a json data to Couchbase bucket/document. I don't know exactly why it is throwing error as "XMLHttpRequest send Failed to load resource: the server responded with a status of 405 (Method Not Allowed)"
When I tested this, it is working fine through Postman
.
var params = {
"EmpID":"567453",
"EmpAddress": "XX",
"EmpAccount": "89723",
"EmpName": "user1953977",
"EmpType": "DEV"
}
var xhr = new XMLHttpRequest();
var url = "http://xxxx:PORT/xxxx/xxx/xxx/docs/docs/firstdoc/"; // Couchbase document url
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Accept", "application/json" );
xhr.setRequestHeader("Authorization", "Basic XXXXXXXXXXXXXXXXXX");
xhr.setRequestHeader("Cache-Control", "no-cache");
var data = JSON.stringify(params);
xhr.send(data)
Can someone advise me where is the issue? Is there way a to fix?