Use post in form to submit large data volumes

Source: Internet
Author: User

In the past, I encountered a problem. When the amount of data sent by the form is large, an error is reported. According to msdn, the reason is that the maximum data size that Microsoft can receive with request. Form () is kb.

Microsoft recommends request. binaryread () reads form data. However, this method reads binary data and needs to analyze the read data in bytes, generate a meaningful string (this is the case for a program on msdn, but it does not take into account escape characters such as punctuation marks for special analysis ). If this method is barely available for a pure English system, it will be very troublesome for the Chinese system because Chinese characters are represented in two bytes, the read binary data itself cannot determine whether it is English or Chinese characters (otherwise it is not binary data, but a string ^-^ ). In this way, you must understand the encoding rules of Chinese characters before analysis. Finally, even if the algorithm can analyze all these data, you can think about the efficiency of analyzing a mega string in MB by byte? Therefore, this cannot be achieved!

However, there are always methods. At first, I thought that the total data in the entire form could not exceed kb. Later I found that this was a limit on each field in the form. The solution is to split the data in a field that needs to send big data into smaller than the quota before submitting the form, and put the data in several hidden domains respectively, at the same time, empty the original domain and then formally submit the form. The server still uses request. Form () to read data from various den domains, and then concatenates them in order. The main code is as follows:

Note: You must specify a DIV in the HTML code of form to dynamically Insert the hidden field to it.
==== Client sample code ====
<Script language = JavaScript>
// Split the data and place it in the corresponding hidden domain.
Function fnprehandle ()
{
VaR icount; // The number of fields to be split.
VaR strdata; // raw data
VaR imaxchars = 50000; // considering that the Chinese character is double byte, the maximum number of characters in the domain is 50 K.
VaR ibottleneck = 2000000; // if the number of characters in the article exceeds 2 MB, You need to prompt the user
VaR strhtml; // raw data
Strdata = frmtest. bigfield. value; // if the article is too long, remind the user
If (strdata. length> ibottleneck)
{
If (confirm ("the article you want to publish is too long. We recommend that you split it into several parts for release. /N if you insist on submission, note that it takes a long time to submit successfully. /N do you insist on submitting? ") = False)
Return false;
} Icount = parseint (strdata. Length/imaxchars) + 1; // hdncount records the number of subdomains in the original data domain
Strhtml = "<input type = hidden name = hdncount value =" + icount + ">"; // generate HTML code for each subdomain
For (VAR I = 1; I <= icount; I ++)
{
Strhtml = strhtml + "/N" + "<input type = hidden name = hdnbigfield" + I + "> ";
} // Dynamically insert HTML code of each den field in the form Div (divhidden)
Document. All. divhidden. innerhtml = strhtml; // assign values to subdomains
For (VAR I = 1; I <= icount; I ++)
{
Frmtest. elements ["hdnbigfield" + I]. value = strdata. substring (I-1) * imaxchars, I * imaxchars );
} // Clear the original data domain
Frmtest. bigfield. value = "";
}
</SCRIPT>
 
=== Server Sample Code ====
<%
Dim strdata
Dim intfieldcount
Dim iintfieldcount = request. Form ("hdncount") for I = 1 to intfieldcount
Strdata = strdata & request. Form ("hdnbigfield" & I)
Nextresponse. Write strdata
%>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.