jqeury中ajax的表單實現異步提交

jQuery異步提交form表單

 


<script type="text/javascript"src="<%=request.getContextPath()%>/js/jquery-1.4.2.js"></script>

然後在jQuery的ready方法中定義form提交時的動作就可以了,

$(document).ready(function() {

// 使用 jQuery異步提交表單

$('#editRealMsgForm').submit(function() {

jQuery.ajax({

url:'editRealMsg.eri',

data:$('#editRealMsgForm').serialize(),

type:"POST",

beforeSend:function()

{  

$('#submitButton').hide();

$('#editRealMsgImg').show();

},

success:function()

{

$('#editRealMsgImg').hide();

$('#modifyButton').show();

$('#realName').attr("disabled","true");

$('#tel').attr("disabled","true");

}

});

returnfalse;

});

});

現在這個form就綁定好jQuery封裝的異步提交方法了,簡單吧!

 

 

 

 

=====================================================

the secondmethod

    no input id

=======================================================

Jquery來對form表單提交(mvc方案)

Jquery來對form表單提交,下面是一個form表單,裏面沒有action字段,我們來用Jquery註冊事件進行提交,
 

<form method="post"id="documentForm">
   <input type="hidden" id="hidId" name="hidId"value="<%=Request.QueryString["id"]%>" />
   <input type="hidden" id="hidAction" name="hidAction"value="<%=Request.QueryString["action"]%>" />
   <divclass="fieldbody">        
       <div class="tagsiglebody">
           <table class="create">
               <tr>
                   <th class="w100">
                       關鍵字:
                   </th>
                   <td class="nes">
                       <input type="text" id="txtKeyword" name="txtKeyword"class="txt w250" value="<%=ViewData.eval_r("keywords") %>"
                           isnull="0" />
                       關鍵字請用逗號隔開
                   </td>
               </tr>              

發佈了102 篇原創文章 · 獲贊 2 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章