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

319
Visualizações
Call do_action using JavaScript/jQuery

I have an AJAX function that sends information to the userpro_ajax_url after successfully logging in through Facebook.

I am trying to get the success block to run a do_action function using

<?php 
ob_start();  
do_action('userpro_social_login', <email needs to go here>);
ob_clean();
?>

Right now if I pass the email address manually it works fine, however the only way I can get the email dynamically is through the current response which is in JavaScript.

The full function is:

FB.api('/me?fields=name,email,first_name,last_name,gender', function(response) {
    jQuery.ajax({
        url: userpro_ajax_url,
        data: "action=userpro_fbconnect&id="+response.id+"&username="+response.username+"&first_name="+response.first_name+"&last_name="+response.last_name+"&gender="+response.gender+"&email="+response.email+"&name="+response.name+"&link="+response.link+"&profilepicture="+encodeURIComponent(profilepicture)+"&redirect="+redirect,
        dataType: 'JSON',
        type: 'POST',
        success:function(data){
            userpro_end_load( form );
            <?php 
            ob_start();  
            do_action('userpro_social_login', );
            ob_clean();
            ?>
            /* custom message */
            if (data.custom_message){
                form.parents('.userpro').find('.userpro-body').prepend( data.custom_message );
            }
            /* redirect after form */
            if (data.redirect_uri){
                if (data.redirect_uri =='refresh') {
                    //document.location.href=jQuery(location).attr('href');
                } else {
                    //document.location.href=data.redirect_uri;
                }
            }
        },
        error: function(){
            alert('Something wrong happened.');
        }
    });
});

I tried running the php action using:

jQuery(document).trigger('userpro_social_login', response.email);

Neither of these work... what am I doing wrong?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Modify your php function userpro_fbconnect trigger the code there or create another ajax request after this one is done

over 4 years ago · Santiago Trujillo Relatório

0

You can't execute PHP code from your JS and vise versa. But the following may help you:

<?php
   // Some php code goes here...
?>
<script>
   // JS code...
   ob_start();                                                                    
   do_action('userpro_social_login', <?php <email needs to go here> ?>);
   ob_clean();
</script>

And if you want to execute a method from your JS, and that method in defined using PHP, and it to the global scope, then simply call it from JS my_global_method()

I hope that helps fixing your problem.

over 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