浠ヤ笅鏄娇鐢 ASP.NET 鐨勭ず渚嬩唬鐮佹潵澶勭悊澶氭潯璁板綍骞跺皢鍏朵繚瀛樺埌鏁版嵁搴撲腑銆 <%@ Page Language="C#" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <%-- 鍦ㄨ繖閲屾坊鍔犺〃鍗曞瓧娈 --%> <input type="text" name="name[]" /> <br/> <input type="text" name="age[]" /> <br/> <input type="submit" value="鎻愪氦" onclick="return saveData();" /> </div> </form> <!-- JavaScript --> <script language="javascript" type="text/javascript"> function saveData() { var names = document.getElementsByName("name[]"); // 鑾峰彇鎵鏈夊悕绉拌緭鍏ユ鍏冪礌 var ages = document.getElementsByName("age[]"); // 鑾峰彇鎵鏈夊勾榫勮緭鍏ユ鍏冪礌 if (names.length != ages.length) { alert('杈撳叆涓嶅畬鏁达紒'); return false; } var dataToSave = []; for(var i=0; i<names.length; i++) { var obj = {}; obj['name'] = names[i].value; obj['age'] = ages[i].value; dataToSave.push(obj); } $.ajax({ url: 'save_data.aspx', // 鍚庡彴澶勭悊椤甸潰鐨 URL method: "POST", // HTTP 璇锋眰绫诲瀷涓 POST contentType: "application/json", // 璁剧疆鍐呭绫诲瀷涓 JSON data: JSON.stringify(dataToSave), // 鍙戦佽淇濆瓨鐨勬暟鎹紙杞崲鎴 JSON锛 success: function(response){ console.log(response); // 鎵撳嵃鏈嶅姟鍣ㄨ繑鍥炵殑缁撴灉 alert('鏁版嵁宸蹭繚瀛橈紒'); // 鏄剧ず淇濆瓨鎴愬姛娑堟伅 }, error: function(){ alert('淇濆瓨澶辫触锛'); // 鏄剧ず淇濆瓨澶辫触娑堟伅 } }); return false; } </script> </body> </html> 涓婅堪浠g爜鍖呭惈浜嗗墠绔 HTML 閮ㄥ垎鍜 JavaScript 閮ㄥ垎銆傚綋鐐瑰嚮鈥滄彁浜も濇寜閽椂锛孞avaScript 鍑芥暟 saveData() 浼氳璋冪敤銆傝鍑芥暟棣栧厛閫氳繃 document.getElementsByName 鏂规硶鑾峰彇鎵鏈夊悕绉板拰骞撮緞杈撳叆妗嗙殑鍊硷紝鐒跺悗鍒涘缓涓涓璞℃暟缁 dataToSave 鏉ュ瓨鍌ㄦ瘡涓緭鍏ラ」鐨勪俊鎭傛帴涓嬫潵锛屼娇鐢 jQuery 鐨 AJAX 鏂规硶鍚戝悗鍙板鐞嗛〉闈㈠彂閫 POST 璇锋眰锛屼紶閫掕淇濆瓨鐨勬暟鎹傛渶鍚庢牴鎹湇鍔″櫒杩斿洖鐨勭粨鏋滆繘琛岀浉搴旀搷浣滐紝濡傛樉绀轰繚瀛樻垚鍔熸垨澶辫触鐨勬秷鎭
浠ヤ笂灏辨槸ASP.NET 澶氭潯璁板綍鍚屾椂淇濆瓨鏁版嵁搴撶殑璇︾粏鍐呭锛屾洿澶氫俊鎭鍏虫敞OD浜戝叾瀹冪浉鍏虫枃绔狅紒