简体   繁体   中英

Download Json as file: IE-11 throwing 414 Request-URI Too Large

I am trying to download json object as cvs file. This JSON object is actually made out of a Java object that is in the browser itself. I am not firing any network request to get.
It is working fine in Chrome but IE-11 throws below error in Network->Response tab.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>414 Request-URI Too Large</title> 
</head><body> 
<h1>Request-URI Too Large</h1> 
<p>The requested URL's length exceeds the capacity 
limit for this server.<br /> 
</p> 
<hr> 
<address>Omniture DC/2.0.0 Server at *.112.2O7.net Port 80</address> 
</body></html>

In the console , I am getting this.

The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337

My code in javascripts is as below:

  var fileName = "Group Assignment";
        var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
        var link = document.getElementById('download-as-csv');   
        link.href = uri;
        link.download = fileName + ".csv";
        link.innerHTML = 'Download as CSV';

I'm afraid you can do that in this way. Microsoft Internet Explorer has a limit up to 2048 characters for URIs.

Instead it should be better you serve this CSV from a diferent page and point IE to get from there or use msSaveOrOpenBlob example:

navigator.msSaveOrOpenBlob(new Blob(CSV.split('')), { type: 'text/csv' }), fileName + ".csv");

*works only from IE 10 and above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM