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

245
Views
Run PHP Script using an external Javascript file in HTML

I have an external Javascript file initialize_database.js that uses JQuery to call a PHP script to create a database and some tables. I've tested my PHP script by adding some HTML to it to run it on its own, and it works fine. My HTML is as follows:

<!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>

Here is initialize_database.js:

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

I'd like to have the Javascript run as soon as the page loads so that the database can be created right away. All files are in the same directory. What am I doing wrong?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Comma and function initialization is required after the URL for executing the function correctly.

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

Check this

about 4 years ago · Santiago Trujillo Report

0

you can use this code . if you want to run when dom ready then

$(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!