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

127
Visualizações
jQuery ajax not working when trying to call php function

I'm trying to call php function from my JavaScript script. I've read several questions on how to call a php function using jQuery ajax. I simply copied most of the content and adapted it to fit my script, but somehow it's not working.

Here's my code:

    var var1 = document.getElementById("tag").value;
    var id = tag.id;
    var var3 = tag.checked;
    var test = $.ajax({
        url: '../PHP/phpFunc.php',
        type: 'GET',
        data: {param1: var1, param2: id, param3: var3},
        complete: function() {
            if(window.console) {
                console.log("success");
            }
        },
        error: function() {
            if(window.console) {
                console.log("Error");
            }
        }
    })

and the php code:

<?php

echo "<script>
     console.log(\"test\")
     </script>";
    $var1= $_GET['param1'];
    $var2 = $_GET['param2'];
    $var3 = $_GET['param3];
    $var4 = '../XML/user/'. $username .'.xml';
   
    //some things are done here 

?>

the "success" is being printed when the JS function is executed, but php code never returns the desired output.

about 4 years ago · Juan Pablo Isaza
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