vendredi 30 décembre 2022

Ajax call on checking checkbox, how to catch data? [duplicate]

I use the following code:

<script>
    $(document).ready(function() {
  $('.model').click(function() {
    var formData = $('#myForm').serialize();
    console.log('Posting the following: ', formData);
    
    $.ajax({
      url: 'av_check.php',
      data: formData,
      type: 'post',
      dataType: 'html',
      success: function(data) {
        $('#html-container').html(data);
      }
    });
  });
});
</script>

When I check a checkbox, it sends model=VALUE to av_check.php But when I select multiple checkboxes, it sends the data like this:

?model=VALUE&model=VALUE&model=VALUE

But when I return $_POST['model'] , it just returns the first value of MODEL. What can I do to read / use all the MODEL values.

See attachment for screenshot of the console log.

Console Log

I think it is more easy to use Json, but when I change dataType to Json, I don't get a response back to show in the DIV on the page that makes the call.




Aucun commentaire:

Enregistrer un commentaire