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

247
Views
Ejecute PHP Script usando un archivo Javascript externo en HTML

Tengo un archivo Javascript externo initialize_database.js que usa JQuery para llamar a un script PHP para crear una base de datos y algunas tablas. Probé mi script PHP añadiéndole algo de HTML para ejecutarlo por sí solo, y funciona bien. Mi HTML es el siguiente:

 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <title>Test Webpage</title> </head> <body> <script src="initialize_database.js"></script> <div> <h2>Nothing here yet!</h2> </div> </body> </html>

Aquí está initialize_database.js :

 $(document).ready(function() { $.get('testPhp.php' { alert('Databases were initialized'); }); });

Me gustaría que Javascript se ejecute tan pronto como se cargue la página para que la base de datos se pueda crear de inmediato. Todos los archivos están en el mismo directorio. ¿Qué estoy haciendo mal?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Se requiere la inicialización de función y coma después de la URL para ejecutar la función correctamente.

 $(document).ready(function() { $.get('testPhp.php', function() { alert('Databases were initialized'); }); });

Mira esto

about 4 years ago · Santiago Trujillo Report

0

Puedes usar este código. si quieres correr cuando dom esté listo, entonces

 $(document).ready(function() { $.get('testPhp.php', function() { alert('Databases were initialized'); }); }); if you want to run this full load then use bellow $( window ).load(function() { $.get('testPhp.php', function() { alert('Databases were initialized'); }); });
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!