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

251
Vistas
xmlHTTPRequests code not working to fetch json from jsonbin

I am going to fetch a json file from jsonbin when clicking a button, but it is not working, your help is appreciated.

<button id="runxhr">RUN XHR</button>
<div id="main"></div>

js file is here:

function runXHR() {


let xhr = new XMLHttpRequest();
  addListeners(xhr);
  xhr.open(
    "GET",
    "https://api.jsonbin.io/v3/b/62b4395c449a1f3821167058/",
    true
  );
  xhr.setRequestHeader("X-Bin-Meta", "false");
  xhr.send();
  return xhr.responseText;
}

function addListeners(xhr) {
  xhr.addEventListener("loadend", display(xhr));
}

function display(jsonstring) {
  let main = document.getElementById("main");
  json = JSON.parse(jsonstring);
  main.innerHTML = json[0]["name"];
}

const buttnRun = document.getElementById("runxhr");
buttnRun.addEventListener("click", () => {
  runXHR();
});
about 4 years ago · Juan Pablo Isaza
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