W
W
wanderbit2016-05-03 11:21:55
PHP
wanderbit, 2016-05-03 11:21:55

Passing variable value from js to php?

How to pass variable value to php variable without reload? (wordpress)
idblock variable to pass

<script type="text/javascript">

      jQuery(document).ready(function(){
        jQuery(".page-numbers").click(function(){
      var idblock = jQuery("div.vc_tta-panel.vc_active").attr("id");
      alert(idblock);
      });
  });

</script>

<nav class="woocommerce-pagination">
  <?php


    echo paginate_links( apply_filters( 'woocommerce_pagination_args', array(
      'base'         => esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
      'format'       => '',
      'add_args'     => false,
      'current'      => max( 1, get_query_var( 'paged' ) ),
      'total'        => $wp_query->max_num_pages,
      'prev_text'    => '&larr;',
      'next_text'    => '&rarr;',
      'type'         => 'list',
      'end_size'     => 3,
      'mid_size'     => 3,
      'add_fragment' => "$idblock"
    ) ) );
  ?>
</nav>


<script type="text/javascript">

      jQuery(document).ready(function(){
        jQuery(".page-numbers").click(function(){
      var idblock = jQuery("div.vc_tta-panel.vc_active").attr("id");
      jQuery('a.page-numbers').attr('href', jQuery('.this').attr('href') + '/#' + idblock);
      alert(idblock);	    
      });
  });

</script>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2016-05-03
@GavriKos

ajax

W
wanderbit, 2016-05-03
@wanderbit

done through cookies

T
ThunderCat, 2016-05-03
@ThunderCat

ok, what's the point? You not only need to transfer, but as I understand it, you also want to return something from the script? They wrote to you, see how to work with Ajax, it is just for these purposes, there are a lot of available examples, there is documentation, it is normally registered in jkveri. Write the question correctly, what do you want to achieve, otherwise it is clear that you are not very versed in technologies, it seems that you do not really understand the goal either.
In this case, you do not need to pass anything to the php script, because. at the time of the formation of the pagination, he had already worked out and sent the pagination data to the page.
Now these values ​​are displayed in the html document as links. To change their values ​​you only need JS, look in Google "how to change the URL of a link using jQuery" for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question