jquery - Loop through AJAX posted array of checkboxes with PHP -
i've spent quite bit of time looking how this. basically, have few checkboxes sending through ajax php script, , want php script echo value of each selected checkbox.
here code checkboxes:
while ($template = $stmt->fetch(pdo::fetch_assoc)){ echo("<input class='checkbox templateselectbox' name='relatedtemplates[]' data-template='". $template['id'] ."' value='".$template['id']."' type='checkbox'> <p class='label label-default'>". $template['name'] ."</p><br>"); }
with php code, there 3 checkboxes on page. here ajax sends checked checkboxes:
$.ajax({ type: 'post', url: 'inc/ajax/addserver.ajax.php', data: {'selectedtemplates': $(".templateselectbox:checked").serialize()}, success: function(data){ $("#responses").html(data); } })
then if check second checkbox , echo using echo($_post['selectedtemplates'])
, echoes relatedtemplates%5b%5d=2
, don't understand why. i'm expecting value of checkbox, single digit. instead i'm getting string.
Comments
Post a Comment