Hello everyone, I ran into a problem with my AJAX request that passes to the ID handler:

<input type="checkbox" onclick="dels('.$reblogs['blog_id'].');"> 

This ID needs to be written to an array. And there are a lot of such input.

 function dels(id) { $.ajax({ type: 'POST', url: '/ajax/test5.php', data: { test: id }, success: function(data) { var x = id; $('.results152d').html(data); } }) } 

Here, actually, AJAX. I can not understand how it is possible to add an array. Prompt, it transfers one parameter, but it is different $_POST['test']

  • @ Dminko93, If you are given a comprehensive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

Ajax request is how to open a page: one request - one page, once the php script has worked. If you need in php an array of states of all checkboxes, you need to transfer them all at once in one ajax request. Give each checkbox the name name="..." and instead of data: ... something like this:

 data: $('input[type="checkbox"]').serialize(), 

Then all enabled checkboxes will go to the server as "Field-name = on" pairs. Example.

The second point, do not write in each input "onclick" - hang up event handlers with the same jQuery:

 $('input[type="checkbox"]').on('click', function(e){ что делать });