Home >Web Front-end >JS Tutorial >Solution when the amount of data in the URL in window.location.href is too large_javascript skills

Solution when the amount of data in the URL in window.location.href is too large_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:07:421434browse

Let’s talk about the problems we encountered today

A process of exporting excel requires transferring a large amount of data to the background after pressing the button. The initial approach is as follows:

Copy code The code is as follows:

var actionUrlSetData = "****Action!exportDatas. action" "?now=" new Date().getTime();
window.location.href= actionUrl "&" data;

The data above is a very long string.

There is no problem in Firefox and Google Chrome, but it cannot be exported normally in IE9 (I haven’t tried it on other IEs, it should be the same)

The reason for this problem is that various browsers have different length limits for URL parsing. IE is the smallest one, so something went wrong


Microsoft Internet Explorer (Browser)
IE browser has a maximum URL limit of 2083 characters. If this number is exceeded, the submit button will not respond.

Firefox (Browser)
For Firefox browser URL length limit is 65,536 characters

Safari (Browser)

The maximum URL length limit is 80,000 characters.

Opera (Browser)

The maximum URL length is limited to 190,000 characters.

Google (chrome)

The maximum length of URL is limited to 8182 characters

It should also be noted here that the WEB server also has restrictions on the length of the URL! !

Therefore, we can no longer use the Get method. We can only find a way to use post to pass the value, so we have the following solution. I am not sure whether it is appropriate or not. Please give some advice from experts. In short, the function can be realized

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

in the callback method of post

The code is as follows:

Copy code The code is as follows:

$.post(actionUrlSetData,mapList,function(){
var actionUrl = path "/***action!exportDatas.action" "?now=" new Date().getTime();
                                      var actionUrl = path "/***action!exportDatas.action" "?now=" new Date().getTime();
                                                              var actionUrl = path "                                                                         " 🎜> });
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn