To pass an array variable from a form through jQuery's ajax() method, you can serialize the form data and send it as the data parameter. Here's an example:

<form id="myForm">
  <input type="text" name="name" value="John">
  <input type="text" name="age" value="30">
  <input type="checkbox" name="hobbies[]" value="Reading" checked>
  <input type="checkbox" name="hobbies[]" value="Sports" checked>
  <input type="checkbox" name="hobbies[]" value="Music">
</form>


var form = $('#myForm');
var formData = form.serialize();

$.ajax({
  url: 'example.php',
  method: 'POST',
  data: formData,
  success: function(response) {
    // Handle the response from the server
    console.log(response);
  },
  error: function(xhr, status, error) {
    // Handle any errors that occur during the AJAX request
    console.log(error);
  }
});



  • No labels