2010-07-31 129 views

回答

6

可能,這將幫助:

$('#submitButtonID').click(function(){ 
alert('Please wait while form is submitting'); 
$('#formID').submit(); 
}); 
+2

'.clickfunction()'?你的意思是'.click(function(){' – Harmen 2010-07-31 09:09:18

+0

@Harmen ..是的,輸入錯誤。謝謝 – sTodorov 2010-07-31 09:18:27

+0

@Gaby感謝編輯 – sTodorov 2010-07-31 09:19:09

10

您在submit按鈕通常的形式提交到服務器和所有客戶端腳本執行單擊停止後。所以,除非你AJAX化你的表單,否則無法工作。爲了AJAXify你的表格,你可以連接到submit事件,並替換默認動作:

$(function() { 
    $('#theForm').submit(function() { 
     // show a hidden div to indicate progression 
     $('#someHiddenDiv').show(); 

     // kick off AJAX 
     $.ajax({ 
      url: this.action, 
      type: this.method, 
      data: $(this).serialize(), 
      success: function() { 
       // AJAX request finished, handle the results and hide progress 
       $('#someHiddenDiv').hide(); 
      } 
     }); 
     return false; 
    }); 
}); 

和您的標記:

<form id="theForm" action="/foo" method="post"> 
    <input name="foo" type="text" /> 
    <input type="submit" value="Go" /> 
</form> 

<div id="someHiddenDiv" style="display: none;">Working...</div> 
4

Ajaxifying不需要形式。您可以在提交期間顯示隱藏的div元素。只要服務器端沒有發回任何響應,瀏覽器將繼續顯示初始頁面。

您可以使用CSS display: none來初始隱藏一個元素。您可以使用jQuery.show()來顯示與選擇器匹配的元素。

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <title>SO question 3377468</title> 
     <script src="http://code.jquery.com/jquery-latest.min.js"></script> 
     <script> 
      $(document).ready(function() { 
       $('#form').submit(function() { 
        $('#progress').show(); 
       }); 
      }); 
     </script> 
     <style> 
      #progress { 
       display: none; 
       color: green; 
      } 
     </style>    
    </head> 
    <body> 
     <form id="form" action="servlet-url" method="post"> 
      ... 
      <input type="submit"> 
     </form> 
     <div id="progress">Please wait...</div> 
    </body> 
</html> 

所以,只要你是not using scriptlets in JSP跑業務繁忙的東西,而是一個servlet類這又顯示了JSP在處理結束時,它會像您期望的工作。

相關問題