【问题标题】:Ajax auto form submitAjax 自动表单提交
【发布时间】:2023-03-06 01:38:01
【问题描述】:

有谁知道如何通过 AJAX 自动提交表单,而无需显式单击提交按钮。

例如,假设我有以下表格:

<form id="form1" method="post" action="" name="form1">

Rows: <input type="text" name="rows" id="rows" /> <br/ >

Columns<input type="text" name="columns" id="columns"> <br/>

</form>

当用户填写列文本框时,我希望提交表单。 我知道如何使用 AJAX,但我希望它在列上的 keyup 事件上触发。

【问题讨论】:

    标签: jquery html ajax forms


    【解决方案1】:

    最好的方法是使用 Columns 输入上的 OnChange 事件。也许确保行也填写了有效数据,然后触发 Ajax 调用。

    喜欢:

    $("input#columns").change(function() {
    // if rows is filled out {
    $.ajax({
    type: 'post',
    url: $("#form1").attr('action')
    etc etc
    })
    })
    

    【讨论】:

      【解决方案2】:

      您可以在另一个函数中定义 $.ajax... 函数

      function submitForm(){
         $.ajax...
      }
      

      那么,你可以随时调用这个函数。

      $('.column').keyup(function(){
         submitForm();
      });
      

      【讨论】:

        猜你喜欢
        • 2013-10-21
        • 2015-12-20
        • 2011-09-25
        • 1970-01-01
        • 1970-01-01
        • 2019-01-09
        • 2015-09-24
        • 1970-01-01
        相关资源
        最近更新 更多