Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

249
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda