I attempted to make an AJAX call in a JavaScript file to fetch data from CouchDB.
Unfortunately, I encountered a 401 error message:
Failed to load resource: the server responded with a status of 401 (Unauthorized)
This is an extract of my JavaScript code:
var locate_data = $.ajax({
url: 'http://admin:mypassword@localhost:5984/database_name',
type:'GET',
dataType: "json",
success: function(data){
console.log("successfully loaded."),
alert(data);
},
error: function(xhr) {
console.log("error"),
alert(xhr.statusText)
}
})
I can successfully retrieve the data from CouchDB using 'curl GET' command in the terminal.
What could be causing this problem? And how do you suggest I resolve it?