Send multiple fields with the same name via jQuery
how to send multiple fields with the same name via jQuery like this:
<input type="text" name="text[]" />
<input type="text" name="text[]" />
<input type="text" name="text[]" />
jQuery:
function upload() {
$.post('example.php', { text[]: Form开发者_StackOverflow中文版.text[].value },
function(output) {
$('#result').html(output).show();
});
}
upload.php:
text[$i] = $_POST['text'][$i];
thank you,
EDIT: correct my question.
I believe that serialize() will do the right thing and produce the appropriate form parameters for such a set of inputs.
$(function() {
$('form').submit( function() {
$.post( 'foo.php', $('[name^=bar]').serialize(), function(data) {
alert(data);
});
return false;
});
});
精彩评论