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

103
Vistas
Problem with a function taken as a function parameter that takes AJAX as its own parameter

I can console.log(arg) but not arg.response. Curious what is the reason behind // edit: when I console log arg I can clearly see response property with data

   function doAjax(param, lambda) {
        let _xhttp = new XMLHttpRequest();
        _xhttp.open("GET", param, true);
        _xhttp.send();
        _xhttp.onload = lambda(_xhttp);
    }
    
    doAjax("ALL_FRAMES", function(arg) {
         console.log(arg.response); --> prints blank field in console
         //allFrames = JSON.parse(arg.response);
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

_xhttp.onload = lambda(_xhttp);

This means "call lambda(_xhttp) immediately, and then assign its return value to _xhttp.onload". You instead want to assign a function to onload, and that function will call lambda later on:

_xhtttp.onload = () => lambda(_xhttp);

// edit: when I console log arg I can clearly see response property with data

That is just a quirk of the way the dev tools handle logging objects. When logging an object, the object is not evaluated until you click on the object in your dev tools. So at the time the console.log ran it didn't have the response yet, but by the time you click, it does have it.

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