Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Get 401 when using ajax call to retrieve data from couchdb

I try to use ajax call in js file to retrieve data from couchdb.

But I got the 401 error: Failed to load resource: the server responded with a status of 401 (Unauthorized)

Here is my js 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 use 'curl GET' to get the data from couchdb by using the terminal.

What is the problem? and how can I fix it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use Basic access authentication where requests contain a header field in the form of Authorization: Basic <credentials>, where credentials is the Base64 encoding of username and password, joined by a single colon ':'.

This answer explains how to do the same in the context of Angular. I'm not using Ajax myself but I suppose it should look something like this.

$.ajax({
  url: 'http://localhost:5984/database_name',
  type:'GET',      
  headers: {
    'Accept': 'application/json',
    'Content-type', 'application/json',
    'Authorization': 'Basic ' + btoa("<username>:<password>")
  },
  xhrFields: {
      withCredentials: true
  },
  ...
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!