The solution when the amount of data in the url in window.location.href is too large

  • 2020-03-30 01:01:57
  • OfStack

Let's talk about today's problem first

For the processing of exporting excel, a large amount of data needs to be transferred to the background after the button is pressed. The initial method is as follows:

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

The data above is just a long string.

This works fine in firefox and Google, but it won't work in ie9 (the other ie didn't try, so it shouldn't)

The reason for this problem is that different browsers have different length limits on URL resolution, and ie is the smallest, so there is a problem

Microsoft Internet Explorer (Browser)
Internet explorer limits urls to a maximum of 2083 characters, and if they exceed that, the submit button doesn't respond.

Firefox (Browser)
The length limit for Firefox browser urls is 65,536 characters

Safari (Browser)

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

Opera (Browser)

The maximum length limit for urls is 190,000 characters.

Google (chrome)

The maximum length limit for urls is 8,182 characters

Also note that the WEB server has a limit on the length of the URL!!

Therefore can not use the Get method, can only think of a way to use post to pass the value, so there is the following scheme, I do not know whether, also ask the master to give directions, in short, the function can be achieved

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

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 articles: