weixin_33721344 2015-11-20 14: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 14: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.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改