2010-10-02 196 views
0

有誰知道如何通過AJAX自動提交表單,而無需顯式點擊提交按鈕。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,但我希望它在列上的按鍵事件上觸發。

回答

1

最好的方法是使用列輸入上的OnChange事件。也許確保行也填寫有效數據,然後觸發Ajax調用。

像:

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

您可以定義$就...功能的其他功能

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

裏面那麼,只要你喜歡,你可以調用這個函數。

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