Update a PHP variable type array using JQuery

1

I have a plugin in wordpress that runs some counters:

My question is whether it is possible to update this variable with JQuery through an event, for example by clicking on the heart icon. I do not pretend that they do the work to me, only that they tell me if it is possible and more or less an example of how to do it, I am not an expert in PHP and less in JQuery.

Thank you in advance.

PHP File:

if(isset($count_options['font-color']) && $count_options['font-color'] != ''){
    $dynamic_css[] = "color: {$count_options['font-color']};";
}

if(isset($count_options['animation']['enable'])){
    $data_animation = "data-enable='on'";
}else{
    $data_animation = "data-enable='off'";
}

if(isset($count_options['animation']['enable'])){
    if(isset( $count_options['animation']['delay'] ) && $count_options['animation']['delay'] !='' ){
        $data_delay = "data-delay='{$count_options['animation']['delay']}'";
    }else{
        $data_delay = '';
    }

    if(isset( $count_options['animation']['duration'] ) && $count_options['animation']['duration'] !='' ){
        $data_duration = "data-duration='{$count_options['animation']['duration']}'";
    }else{
        $data_duration = '';
    }
}else{
    $data_delay = '';
    $data_duration ='';
}
if ($counter == 2) {
    $count_options['content'] = $count_prayer * 3;      
}   
?>
<div class="ec-count-content"><span class="ec-count-number" <?php echo $data_animation; echo $data_delay; echo $data_duration; ?> ><?php echo esc_attr($count_options['content']); ?></span><?php if($template == 'template12'){ ?><span class='ec-count-sign'>+</span><?php } ?></div>
<?php
if(isset($count_options['font-family']) && $count_options['font-family'] !=''){
    if(!in_array( $count_options['font-family'], $google_fonts_used_array) ){
        array_push($google_fonts_used_array, preg_replace('/\s/', '+', $count_options['font-family']) );
    }
    $dynamic_css[] = "font-family: {$count_options['font-family']};";
}

if(!empty($dynamic_css)){
    $dynamic_css = implode(' ', $dynamic_css);
}else{
    $dynamic_css ='';
}

ob_start();
?>
.ec-<?php echo $template; ?> .ec-counter-item-<?php echo $counter; ?> .ec-count-content .ec-count-number { <?php echo esc_attr($dynamic_css); ?> }

<?php
$ec_dynamic_css_at_end[] = ob_get_contents();
ob_end_clean();

}

    
asked by Melvin Pérez 20.11.2018 в 15:41
source

1 answer

0

By clicking on the button, you will see the information that you will use with ajax: Example:

$('#idDeMiBoton').click(function(){
    var data = {nombre: nombre, tel: tel, email: email, text: texto};//datos que capturas del html si lo necesitas
    $.ajax({
                type: "POST",
                url: "ruta hasta tu fichero php", 
                data: data,
                success: function (response) {
                   //esta funcion se ejecuta cuando la consulta devuel status: 200 "Correcto"
                }
            })
            ; 

});

then in your php code you get the data of the request:

$request->get('nombre');
$request->get('tel');
    
answered by 21.11.2018 в 21:50