2013-01-22 29 views
0

我使用jQuery的表格插件
http://malsup.com/jquery/form/jQuery的表格插件,2個按鈕

<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data"> 
<input name="submit" id="submit1" type="submit" class="submit_button" value="Save" /> 
<input name="submit2" id="submit2" type="submit" class="submit_button" value="Send Sale" /> 
</form> 

好,這樣有兩個按鈕,一個是通過Ajax形式和其他人送郵件是將數據保存到表。這裏是我使用的Jquery。

$(document).ready(function() { 
// bind form using ajaxForm 
$('#submit2').click(function() { 
    alert('ffff'); 
    $('#form1').ajaxForm({ 
     // target identifies the element(s) to update with the server response 
     target: '.loading', 
     beforeSubmit: showImg, 
     success: showResponse, 
     url:  'send_sale.php', 
    }); 
}); 
}); 

當我點擊保存按鈕其工作正常,但是當我在發送售點擊第一,只是在保存按鈕點擊後,保存按鈕做發送出售同樣的過程。

有誰知道最新錯誤?

UPDATE
只是通過被提交表單標籤內的按鈕,這兩個按鈕提交表單獲得的,而不是給ajaxForm

回答

0

解決方案使用ajaxSubmit會。您可能想要嘗試的是將輸入提交轉換爲按鈕並將它們移到窗體外部。

<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data"> 
</form> 
<button id="submit1" class="submit_button">Save</button> 
<button id="submit2" class="submit_button">Send Sale</button> 

然後分別定義您的點擊處理程序。

$(document).ready(function() { 
    $('#submit1').click(function() { 
    alert("action 1") 
    $('#form1').ajaxForm({ 
     target: '.loading', 
     beforeSubmit: showImg, 
     success: showResponse, 
     url: 'send_sale.php', 
    }); 
    }); 
    $('#submit2').click(function() { 
    alert("action 2") 
    }); 
});