java - Unable to POST large html content to server on Chrome -
i'm trying send html content through post request not getting delivered on server side using chrome. while request data in jsp when using mozilla. works in both browsers when html content small. i'm generating pdf html content using apache fop.
var iframe = document.createelement('iframe'); iframe.setattribute('name','eyeframe'); document.body.appendchild(iframe); var myform = document.createelement('form'); document.body.appendchild(myform); myform.setattribute('action','myjsptorenderhtmlaspdf.jsp'); myform.setattribute('method','post'); myform.setattribute('target','eyeframe'); var hiddenfield = document.createelement("input"); hiddenfield.setattribute("type", "hidden"); hiddenfield.setattribute("name", "htmlcontent"); hiddenfield.setattribute("value", strhtml); myform.appendchild(hiddenfield); myform.submit();
i dividing html chunks , posting them , rejoining them in jsp. method of doing fails chrome , ie.
well inputs in chrome (or maybe whole webkit) has limit of chars - 524288, can test typing in console:
var el = document.createelement("input"); el.maxlength
why not use simple formdata?
var formdata = new formdata(); formdata.append("htmlcontent", strhtml); var request = new xmlhttprequest(); request.open("post", "myjsptorenderhtmlaspdf.jsp"); request.send(formdata);
got time write simple demo. server respons generated pdf:
<a href="#" id="test">download</a> <script> var formdata = new formdata(); formdata.append("htmlcontent", 'test'); var request = new xmlhttprequest(); request.responsetype = 'blob'; request.open("post", "myjsptorenderhtmlaspdf.jsp"); request.onload = function(event) { if (request.status == 200) { var blob = new blob([request.response], {type: 'application/pdf'}); var url = url.createobjecturl(blob); var link = document.queryselector('#test'); link.setattribute('href', url); } else { // handle error } }; request.send(formdata, true); </script>
Comments
Post a Comment