Browser crashed - tickboxes array to Ajax (PHP)
When I click on the Add button, the browser (chrome) crashed.
I am trying to send the array of tickboxes (value) to 开发者_开发知识库ajax (PHP).
See the following code:
<input type="checkbox" name="option[]" value="0"> Small
<input type="checkbox" name="option[]" value="1"> Medium
<input type="checkbox" name="option[]" value="2"> Large
<input type="checkbox" name="option[]" value="3"> X-Large
<input id="ButtonAdd" type="button" value="Add" />
jQuery:
$("#ButtonAdd").click(function() {
var optionsz = $("input:checkbox[name='option\\[\\]']");
$.post("ajax.php", { optionsz:optionsz },
function(data) {
console.log(data)
});
});
PHP:
<?php
print_r($_POST);
?>
You are trying to send a jQuery object optionsz
but what you really want to do is serialize the form in which the options reside and send that to the ajax.php script.
var optionsz = $(your form).serialize();
精彩评论