需要使用xmlHttprequest发布大量数据

时间:2010-06-28 12:05:21

标签: javascript-events

我需要将大量数据传递给服务器而不加载页面我有代码

enter code here
                var GlType = "<%=GlType %>";
                var pageUrl = "SelectAccount.aspx?callback=true&AccountList=" +accountList +"&AnalysisDate="+analysisDate+"&GlType="+GlType;
                if (window.XMLHttpRequest)
                 {
                      var xmlRequest = new XMLHttpRequest();
                 }
                else
                 {
                      var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
                 }
                xmlRequest.open("POST", pageUrl, true);
                xmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
                xmlRequest.send(null);

我已经使用查询字符串传递了超出查询字符串的最大长度。请帮助我...

2 个答案:

答案 0 :(得分:1)

由于您已经在使用POST方法,因此您可以在正文中传递数据。

xmlRequest.send("Field1=abc&Field2=def");

您可以检索服务器上的数据,例如在ASP.NET中:

if (Page.Request.Form["Field1"] == "abc") ...

对于GET方法,您只能使用查询字符串来传输数据。

答案 1 :(得分:0)

您是通过邮寄发送请求,但将所有内容放入查询字符串中!

相反,您应该将数据作为请求的主体发送(传递给send方法)。

相关问题