Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda