Jquery Serialize Function With Multiple Values September 29, 2023 Post a Comment I try to use jQuery to post multiple values to PHP page, and then use that values as a single values. I start with code from Jquery site : Solution 1: Change your multiple to multiple[] in your form. This will submit your values as multiple[]=1st value, multiple[]=2nd value and more.jQuery,$('form').on('submit', function(e) { e.preventDefault(); formData=$('form').serialize(); $.ajax( { type: "POST", url: "test.php", data: formData, success: function(data) { alert("Form submitted"); }, error: function() { alert("Error in form submission"); } }); }); CopyAt the PHP end,$multiple=$_POST['multiple']; // Get the array inputCopyNow proceed with the values respectively,foreach($multipleas$key => $value) { echo"value number $key is $value"; // This will print as value number 0 is 1st value, value number 1 is 2nd value and more. } CopySolution 2: You have to post the form to test.php using AJAX. Try this -$("form").on('submit', function(ev){ ev.preventDefault(); var form = $(this); var action = 'test.php'; var data = $(this).serialize(); $.post(action, data) .done(function(response){ if(response.success == false) { // If failed } else { // If successfully submitted } }); }); CopyAnd on the other side (test.php), you'll get an array of your multiple values like this,$multiple1 = $_POST['multiple']['0']; $multiple2 = $_POST['multiple']['1']; Copy Share Post a Comment for "Jquery Serialize Function With Multiple Values"
Post a Comment for "Jquery Serialize Function With Multiple Values"