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

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

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