Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
How to pass JavaScript variables to PHP without reload the page?

i want to assign javascript variable value to php variable to loop products

here is my php code:

$products = wc_get_products( array( 
  'include' => $products_ids // `**i want to pass value from javascript here**`
) );

  foreach ( $products as $product ) {
     // fetching my product details
  }

here is my js code:

  (function($){

    $(document).ready(function(){

      $(document).on('change', '#myform', function(e) {

        
        e.preventDefault();

        data = $(this).serialize();

        var settings = {
            "url": "<?php  echo WC_AJAX::get_endpoint( 'myajaxfunction' ) ?>",
            "method": "POST",
            "data": data,
          }
          $.ajax(settings).done(function (result) {
            // i want to make $products_ids = result
            // result value is array(1,2);
          });
      });
    });
  })(jQuery);

**

  1. i want to make $products_ids = result so i can pass it in my php code,

  2. result value is array(1,2);

**

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!