在jquery中POST多个值,尤其是在名称相同的情况下


POST multiple values in jquery especially if names are the same

我在php中有一个表(NOT FORM),它是我在while循环中生成的。其中一个输入是生成20个输入,其中有或没有任何数据。我正在尝试使用jquery运行更新/保存,我需要在该输入中发布所有值。

这是一个while循环。它基本上是循环并将表中的数据渲染到下面的图像中。如果计算图像中的输入框,则为20。

网页布局

echo '<input type="text" name="access[' . $count . '][' . $a . ']" id="access[' . $ucount . '][' . $a . ']" size="1" maxlength="2" value="' . $user_access[$a] . '" />';

在html页面中,您将看到此

<input type="text" value="RO" maxlength="2" size="1" id="access[2][0]" name="access[2][0]">
<input type="text" value="SQ" maxlength="2" size="1" id="access[2][1]" name="access[2][1]">
and without ant data it will be the `value` will be blank.
<input type="text" value="" maxlength="2" size="1" id="access[2][2]" name="access[2][2]">

现在,因为我正在使用jQueryajax来执行update/save。我将如何通过jQuery发送所有20个输入框中的所有内容?我做了一个正常的,这就是我通常在下面做的。

$(document).ready(function () {
    $('[name="save_record"]').unbind('click').click(function () {
        var update_user = $(this).parent().parent().find('[name="user"]').val();
        $.ajax({
            type: 'POST';
            url: 'update.php';
            data: {
                update_user: update_user
            },
            success: function (Response) {
                alert(Response);
            })
        });
    });

但我知道在所有20个输入框中发布所有值的方法会有所不同,但我已经像上面一样尝试过了,它只在第一个输入框内发布第一个值。

问题如何在所有20个输入框中发布值?请根据你的答案/例子,就好像你的输入框是空的一样。

注意有些值可能是空的,所以我还需要检查输入框是否为空。

感谢

$.post(
    '/my-url',
    {
        data: $('#my-form').serialize()
    },
    function (data) {
        // some processing successful result here
    }
);

使用没有<form><input>标签是不适当的

相关文章: