/* * PostNewWin * Author:ppchen */ var PostNewWin = function (url){ var urlArr = url.split( " ? " ); var postUrl = urlArr[ 0 ]; var postData = urlArr[ 1 ]; var iframe = document.getElementById( " postData_iframe " ); if ( ! iframe){ iframe = document.createElement( " iframe " ); iframe.id = " postData_iframe " ; iframe.scr = " about:blank " ; iframe.frameborder = " 0 " ; iframe.style.width = " 0px " ; iframe.style.height = " 0px " ; var form = document.createElement( " form " ); form.id = " postData_form " ; form.method = " post " ; form.target = " _blank " ; document.body.appendChild(iframe); iframe.contentWindow.document.write( " <body> " + form.outerHTML + " </body> " ); } iframe.contentWindow.document.getElementById( " postData_form " ).innerHTML = " <input name='postData' id='postData' type='text' value=' " + postData + " '/> " ; iframe.contentWindow.document.getElementById( " postData_form " ).action = postUrl; iframe.contentWindow.document.getElementById( " postData_form " ).submit(); };
2.CSharp /// <summary> /// 从Form中取得参数 /// Author:ppchen /// </summary> /// <returns> 参数集合 </returns> private NameValueCollection ParseFormData() { NameValueCollection sQueryString = new NameValueCollection(); if ( this .Request.Form.Count > 0 && this .Request.Form[ " postData " ] != null ) { string sPostData = this .Request.Form[ " postData " ].ToString(); sPostData = sPostData.Trim( new char [] { ' & ' , ' ' }); if ( ! string .IsNullOrEmpty(sPostData)) { string [] sParameterList = sPostData.Split( ' & ' ); for ( int i = 0 ; i < sParameterList.Length; i ++ ) { string [] sParameter = sParameterList[i].Split( ' = ' ); for ( int j = 0 ; j < sParameter.Length; j = j + 2 ) { sQueryString.Add(sParameter[j], HttpUtility.UrlDecode(sParameter[j + 1 ])); } } } } return sQueryString; }
通过以上的JS代码在客户端打开页面,通过以上的CS代码在服务端取得参数,这样使用了POST方式解决了GET方式中URL的长度限制,可以传递大数据量的参数了:)