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

135
Vistas
How to fire $.post when inside function?

I want to fire Jquery to execute php code inside different file. However I cannot find a way to get the Jquery command to execute.

I am using wordpress.

My code inside functions.php

add_action( 'wp_footer', 'mycustom_wp_footer' );    //adding funtion for each form buttom to fire when pressed

    function mycustom_wp_footer() {     //function form each form button to fire when button pressed
        ?>
        <script type="text/javascript">
            var wpcf7Elm = document.querySelectorAll( '.wpcf7' );
            wpcf7Elm.forEach(function(formr){
            formr.addEventListener( 'wpcf7submit', function( event ) {
                    //if ('wpcf7-f101-p97-o1' == event.detail.unitTag) {    //when button inside form with this unitTag is pressed do code bellow

                        var gen3_name = "25";
                        //tis code is not working
                        $(document).ready(function(){   //adding ajax, Jquery to send data to .php file for php function to execute
                            $.post("gen3.php", name: gen3_name);
                        });
                    //tis code is not working
             
                    var idform = event.detail.unitTag;
                    alert (idform);
            }, false ); })
        </script>

My code inside gen3.php

global $wpdb;

if (isset($_POST['name'])) {

    $name = $_POST['name'];
    
    if ($name == "25") {

        $wpdb->update('Gen3', array('tvalue' => 1,), array('id' => 25), array('%d'), array('%d'));

    }

}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Can you tell me what output do you get in your console? Any error or warning? I think your code will be placed before attaching the JQuery file. Put the priority of the hook to a high number which means low priority and it will be placed after attaching the jquery.

add_action( 'wp_footer', 'mycustom_wp_footer', 0, 999999 );

Also because of loading JQuery NoConflict or some other plugins, You might need to use JQuery.method() instead of $.method.

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