我认为最好的方法是使用 Propper Form 并使用jQuery.serializeArray。
<!-- a form with any type of input -->
<form class="a-form">
<select name="field[something]">...</select>
<input type="checkbox" name="field[somethingelse]" ... />
<input type="radio" name="field[somethingelse2]" ... />
<input type="text" name="field[somethingelse3]" ... />
</form>
<!-- sample ajax call -->
<script>
$(document).ready(function(){
$.ajax({
url: 'submit.php',
type: 'post',
data: $('form.a-form').serializeArray(),
success: function(response){
...
}
});
});
</script>
这些值将在 PHP 中以$_POST['field'][INDEX]
.