Ajax的自动表单提交(Ajax auto form submit)

2019-11-04 06:50发布

有谁知道如何通过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在列事件。

Answer 1:

最好的办法是利用在列输入OnChange事件的。 也许,确保行还与有效数据填写,然后触发Ajax调用。

喜欢:

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


Answer 2:

您可以定义另一个函数内部的$就...功能

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

然后,你可以调用这个函数,只要你喜欢。

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


文章来源: Ajax auto form submit