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

165
Views
usuario ajax para obtener datos sin la "función onClick" en javaScript

He estado buscando el ejemplo de obtener datos usando ajax sin la función onclick, pero la mayoría de los ejemplos que encontré estaban dentro de la función onclick.
Aquí está el html que obtuve con éxito los datos usando la función Onclick

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>New document</title> <script type = 'text/javascript' src='js/jquery-2.2.0.js'></script> <script type ='text/javascript' src='js/testScript.js'></script> <?php include_once("database_conn_getOffers.php"); ?> </head> <body> content goes here <aside id="offer" onclick ="loadDoc('getData.php',myFunction)"> &nbsp; click here </aside> </body>

aquí está el guión

 function loadDoc(url, cFunction) { var xhttp; xhttp=new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { cFunction(this); } }; xhttp.open("GET", url, true); xhttp.send(); } function myFunction(xhttp) { document.getElementById("offer").innerHTML = xhttp.responseText; }

Ahora, quería obtener los datos sin la función onclick.
Quiero que se muestren los datos una vez que abra el html.
¿Alguien puede proporcionarme algún enlace o darme un ejemplo?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Todo lo que necesita hacer es llamar a la función en otro lugar, por ejemplo, puede configurarla para que se llame cuando se carga la ventana.

Window.onload = loadDoc('getData.php',myFunction)

about 4 years ago · Santiago Trujillo Report

0

Puedes usar

<body onload="loadDoc('getData.php',myFunction);">

about 4 years ago · Santiago Trujillo Report

0

Una tercera solución podría ser agregar un nuevo evento DOMContentLoaded para enviar la consulta después de que el navegador represente la página.

Debería ser algo como esto:

document.addEventListener('DOMContentLoaded', loadDoc);

about 4 years ago · Santiago Trujillo 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!