开发者

Browser crashed - tickboxes array to Ajax (PHP)

开发者 https://www.devze.com 2023-04-04 20:49 出处:网络
When I click on the Add button, the browser (chrome) crashed. I am trying to send the array of tickboxes (value) 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消