ajax中使用post 方式提交表单时能提交多达2GB的内容,而GET方法只能提交最多512KB的内容.以下是ajax POST提交的例子. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Ajax POST方法提交表单</title> <mce:script type="text/javascript"><!-- window.οnerrοr=function(errorMessage,errorUrl,errorNum) { alert(errorMessage+errorUrl+errorNum); } var xmlHttp; function createXmlHttp() { if(window.ActiveXObject) xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); else xmlHttp=new XMLHttpRequest(); } function startRequest() { try { createXmlHttp(); var url="ajax_post.ashx"; var postedData=getRequestBody(document.forms["form1"]); xmlHttp.open("post",url,true); xmlHttp.setRequestHeader("content-length",postedData.length);//post提交设置项 xmlHttp.setRequestHeader("content-type","application/x-www-form-urlencoded");//post提交设置项 xmlHttp.onreadystatechange =onComplete; //将名值对发送到服务器 xmlHttp.send(postedData); } catch(e) { alert(e.message); } } function onComplete() { if(xmlHttp.readyState==4&&xmlHttp.status==200) { //显示结果 document.getElementById("divResult").innerText=xmlHttp.responseText; } } //获取表单中的名值对 function getRequestBody(oForm) { var aParams=new Array(); for(var i=0;i<oForm.elements.length;i++) { var sParam=encodeURIComponent(oForm.elements[i].id) sParam+="="; sParam+=encodeURIComponent(oForm.elements[i].value); aParams.push(sParam); } return aParams.join("&"); } // --></mce:script> </head> <body> <form id="form1"> 要提交的字段落1: <input id="Text1" type="text" /><br /> 要提交的字段落2: <input id="Text2" type="text" /> <br /> <input id="Button1" type="button" value="POST提交" οnclick="startRequest();" /><div id="divResult"></div></form> </body> </html> 服务器端处理代码(ajax_post.ashx): <%@ WebHandler Language="C#" Class="ajax_post" %> using System; using System.Web; public class ajax_post : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write(String.Format("你输入的值是{0}和{1}!",context.Request.Form["Text1"],context.Request.Form["Text2"])); } public bool IsReusable { get { return false; } } }