表單的序列化ajax

來源:互聯網
上載者:User

標籤:返回   ++   html4   back   serial   option   數字   ajax   url   

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <title>Insert title here</title> 6     <script type="text/javascript" src="../js/jquery-1.4.2.js"></script> 7     <script type="text/javascript"> 8         $(document).ready(function(){ 9             $("#ajaxbutton").click(function(){10                 //表單序列化 他返回的是字串11                 //var data = $("#form1").serialize();12                 //序列化成三個資料對象13                 var data = $("#form1").serializeArray();14                 alert(data);//alert:只能列印字串,數字,並不能列印很全面資訊15                 console.info(data);16                 //輸出數組17                 for(var i=0;i<data.length;i++){18                     alert(data[i].name+" : "+data[i].value);19                 }20                 var option ={21                     "url" :"/jquery_day02/FormServlet",22                     "data":data,23                     "type":"POST",24                     "success":function(data){25                         //用於接受伺服器響應的資料26                     }27                     28                 };29                 30                 $.ajax(option);31             });32         }); 33         34         35     </script>36     37 </head>38 <body>39     <h3>表單</h3>40     <form id="form1">41         <table border="1" >42             <tr id="tr1">43                 <td class=""><label>姓名</label></td>44                 <td><input type="text" name="username"  value="jack" /></td>45             </tr>46             <tr>47                 <td class=""><span>密碼</span></td>48                 <td><input type="password" name="password" value="1234" /></td>49             </tr>50             <tr>51                 <td><input type="button"  value= "非同步提交表單"  id="ajaxbutton"/></td>52             </tr>53             54         </table>55     </form>56     57     58     <h3>公告資訊</h3>59     <div>60         未滿18慎進61     </div>62     63         64 </body>65 </html>

 

表單的序列化ajax

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.