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

154
Views
asíncrono no funciona. Intenté usar tanto esperar como prometer para obtener el retorno asíncrono

Prueba asíncrona antes de hacer un código más complejo. Tengo un archivo HTML que intenta obtener un conjunto de datos mediante una función de recuperación asíncrona, ubicada en un archivo Javascript, desde mi base de datos. Quiero almacenar el conjunto de datos en una variable dentro del archivo HTML que luego lo colocaría dentro de una etiqueta de elemento SPAN HTML. Al ejecutar y mirar el registro de mi navegador, puedo ver que el conjunto de datos se ha recuperado de la base de datos, pero no vuelve a almacenarse en la var HMTL. He probado algunas soluciones, pero no han funcionado. Agradecería saber por qué no funcionaron y una solución, por favor.

CÓDIGOS: ARCHIVO HTML:

 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="queryFile.js"></script> </head> <body> <h2>The XMLHttpRequest Object</h2> <h3>Start typing a name in the input field below:</h3> <p>Suggestions: <span id="txtHint"></span></p> <p>First name: <input type="text" id="txt1" ></p> </body> <script> const seeing = getBuyData("fff","2ddds"); console.log(seeing) document.getElementById("txtHint").innerHTML = seeing; </script>

CÓDIGOS: ARCHIVO JAVASCRIPT:

 async function getBuyData(starter, ender) { if (starter.length == 0) { console.log("No Data to POST"); return; } else { const xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function() { var gotten_Text = this.responseText; console.log(gotten_Text) //THIS PART WORKED return gotten_Text; } xmlhttp.open("POST", "getFXData.php?case01=1&str=" + starter + "&ed=" + ender); xmlhttp.send(); } }

LOS SIGUIENTES ABAJO SON MIS INTENTOS DE SOLUCIONES:

1)

 document.getElementById("txtHint").innerHTML = getTheData("fff","2ddds");
 const seeing = getBuyData("fff","2ddds"); console.log(seeing) document.getElementById("txtHint").innerHTML = seeing;
 getBuyData("fff","2ddds").then( function(value) { document.getElementById("txtHint").innerHTML = value;; }, function(error) { console.log(error); } );
 async function getTheData01() { var fstep = await getBuyData("fff","2ddds"); document.getElementById("txtHint01").innerHTML = fstep; }
about 4 years ago · Juan Pablo Isaza
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!