Skip to content Skip to sidebar Skip to footer

Parsing Javascript Array To Php Issue

The problem is that on each button click a new array is created. Is that possible to store all of the button values to a single array? How is that possible. You can see it here I p

Solution 1:

I see your issue here, but the only way to parse a "single" array to php is to convert that into string. Otherwise leave it as it is and process it in PHP as an array.

Here is how to convert your array into string in Javascript:

$('#validate').click(function(e) { 
     let k = items.join("");
      $.ajax({
       type: "POST",
       url: "somephp.php",
       dataType: "json",
       data: {
          UserInput:k
             }
     })
    });

Solution 2:

There a many ways to solve it. Two of them:

  1. Make a .click event for each button.
  2. Make an if statement who compare the id

Post a Comment for "Parsing Javascript Array To Php Issue"