解决get提交数据量太大的问题

xiaoxiao2021-02-28  49

由于参数中是base64编码后的图片数据,图片比较大,导致get请求失败,提示数据太大。

get最大是256b,post是2M。

解决方式:

使用伪post方式:

//上传图片方法 function picUpload(){ var ocrImageSrc = document.querySelector('#ocr_img').childNodes[0].src; //window.parent.self.open(encodeURI((hostUrl+"?reportlet=/CRM/联系人新建_名片信息录入.cpt&op=write&photo="+ocrImageSrc)),"_self"); openPostWindow(encodeURI(hostUrl+"?reportlet=/CRM/联系人新建_名片信息录入.cpt&op=write"),encodeURI(ocrImageSrc),'_parent'); //alert(encodeURI((hostUrl+"?reportlet=/CRM/联系人新建_名片信息录入.cpt&op=write&photo="))); } /**  * 使用post方式打开画面,解决self.open传输数据get方法的传输数据量限制  */ function openPostWindow(url, data, name)           {              var tempForm = document.createElement("form");              tempForm.id="tempForm1";              tempForm.method="post";              tempForm.action=url;              tempForm.target=name;                       var hideInput = document.createElement("input");              hideInput.type="hidden";              hideInput.name= "photo"           hideInput.value= data;            tempForm.appendChild(hideInput);               tempForm.addEventListener("onsubmit",function(){ openWindow(url,name); });            document.body.appendChild(tempForm);                    fireEvent(tempForm,"onsubmit");            tempForm.submit();            document.body.removeChild(tempForm);       }          /**  * 打开画面  */ function openWindow(url,name)         {              self.open(url,name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');          }   

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

重点:可以使用AJAX POST跨域方式,详情请见:http://blog.csdn.net/danfeixia/article/details/71599304

转载请注明原文地址: https://www.6miu.com/read-78785.html

最新回复(0)