的jQuery
$("input[type=checkbox]:checked").live("click", function (e) {
var data = $('.variation:checked').map(function (i, n) {
return {
'val': $(n).val()
};
}).get();
$.post('/variations.php', {
'data': data
}, function (data) {
$('#variations').html(data);
});
});
HTML输出
<div id="variations">
Array
(
[data] => Array
(
[0] => Array
(
[val] => 1
)
)
)
</div>
PHP
print_r($_POST)
问题:如果未选中复选框,如何从POST中删除值?
答案 0 :(得分:3)
使用$('form#myForm').serialize()
发送表单数据
它只会send the checkboxes which are checked
//example 1
$('input#submitButton').click( function() {
$.post( 'some-url', $('form#myForm').serialize(), function(data) {
... do something with response from server
},
'json' // I expect a JSON response
);
});
//example 2
$('input#submitButton').click( function() {
$.ajax({
url: 'some-url',
type: 'post',
// dataType: 'json',
data: $('form#myForm').serialize(),
success: function(data) {
... do something with the data...
}
});
});
来自here
答案 1 :(得分:2)
您可以使用.disable方法来禁用对象,然后在发布完成后启用它们。或者您可以在单击提交按钮时使用方法.click功能,或者如果您不想在您的php中使用此值,您可以取消设置($ _POST ['one some key'])具有未设置功能