Solution _ javascript skills when the volume of url data in window. location. href is too large

Source: Internet
Author: User
This article mainly introduces how to solve the problem when the url data volume in window. location. href is too large. For more information, see the following:

To export an excel file, you need to upload a large amount of data to the background after pressing the button. The procedure is as follows:

The Code is as follows:


Var actionUrlSetData = "***** Action! ExportDatas. action "+ "? Now = "+ new Date (). getTime ();
Window. location. href = actionUrl + "&" + data;

The above data is a long string.

In this way, Firefox and Google browsers are no problem, but ie9 (Other ie did not try, it should be the same) will not be able to export normally

The cause of this problem is that various browsers have different restrictions on URL resolution length. ie is the smallest one, so the problem arises.


Microsoft Internet Explorer (Browser)
The maximum length of a URL in IE is 2083 characters. If this number is exceeded, the submit button does not respond.

Firefox (Browser)
The URL Length of the Firefox browser is limited to 65,536 characters

Safari (Browser)

The maximum length of a URL is 80,000 characters.

Opera (Browser)

The maximum length of a URL is 190,000 characters.

Google (chrome)

The maximum url length is 8182 characters.

Note that the WEB server has a limit on the URL length !!

Therefore, you cannot use the Get method. You can only use the post method to pass the value, so that you can use the following solution. If you do not know whether it is correct, please give pointers. In short, the function can be implemented.

The idea is to use post to upload the long string to the background, save it to the session, and use window. location. href in The post callback method.

The Code is as follows:

The Code is as follows:


$. Post (actionUrlSetData, mapList, function (){
Var actionUrl = path + "/*** action! ExportDatas. action "+ "? Now = "+ new Date (). getTime ();
Window. location. href = actionUrl + "&" + (data );
});

Related Article

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.