Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda