weixin_33721344 2015-11-20 06:41 采纳率: 0%
浏览 15

用AJAX提交动态表单? [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/1960240/jquery-ajax-submit-form" dir="ltr">jQuery AJAX submit form</a>
                            <span class="question-originals-answer-count">
                                (20 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2015-11-20 15:17:31Z" class="relativetime">4 years ago</span>.</div>
        </div>
    </aside>

I am looking to submit a page full of quantities to a page and then return their values. I have the following:

<input type="number" name="item1" />
<input type="number" name="item2" />
<input type="number" name="item3" />
<input type="number" name="item4" />
<input type="number" name="item5" />

AJAX:

function getnames(){
    $.ajax({
          method: 'post','getnames.php',
          data: {
            'order': order,
            'ajax': true
          }
          success: function() {

    });
}
});
}

I want to find a way to post all input fields that contain the string "item" in the name so my question is:

How do I put a variety of input fields into a javascript array and then post them using ajax?

</div>

展开全部

  • 写回答

1条回答 默认 最新

  • weixin_33724659 2015-11-20 06:46
    关注

    You can use the ajaxForm/ajaxSubmit functions from Ajax Form Plugin or the jQuery serialize function.

    AjaxForm:

    $("#theForm").ajaxForm({url: 'server.php', type: 'post'})
    

    or

    $("#theForm").ajaxSubmit({url: 'server.php', type: 'post'})
    

    ajaxForm will send when the submit button is pressed. ajaxSubmit sends immediately.

    Serialize:

    $.get('server.php?' + $('#theForm').serialize())
    
    $.post('server.php', $('#theForm').serialize())
    

    AJAX serialization documentation is here.

    评论
    编辑
    预览

    报告相同问题?

    悬赏问题

    • ¥15 PADS Logic 原理图
    • ¥15 PADS Logic 图标
    • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
    • ¥20 气象站点数据求取中~
    • ¥15 如何获取APP内弹出的网址链接
    • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部