url参数过长处理办法

mac2022-06-30  67

常用的解决办法是将get请求换成post,但是遇到只能用get请求的时候,该怎么解决呢? 答案是: 我们可以借用form表单提交

在开发过程中,遇到这么一个问题:我需要在A点击一个按钮,打开一个新的页面B,但是由于参数过长,导致页面请求失败,找了很多办法,终于解决了

//A页面 function printStoreIn() {   window.open("A.vm?sid="+sid); }

 

<script type='text/javascript'> //B页面 var sid= jQuery.request("sid"); jQuery.ajax({ url: 'XX.do', type: 'post', dataType: 'json', data: { "sid":sid }, success: function (result) { if(result.isOk) { var s =[]; var param; var data = result.data; if (data){ for(var i=0; i<data.length; i++){ param = '&sid='+sid+ '&pid=' + data[i].pid; s.push(data[i].pname+',/simple/v.do?_m=/B.vm'+param); } var tempForm = document.createElement("form"); tempForm.id="tempForm1"; tempForm.method="post"; tempForm.action="/tabs.jsp"; var hideInput = document.createElement("input"); hideInput.type="hidden"; hideInput.name= "tabs"; hideInput.value= Uri(s.join(";")); tempForm.appendChild(hideInput); if(document.all){ tempForm.attachEvent("onsubmit",function(){ }); //IE }else{ var subObj = tempForm.addEventListener("submit",function(){ },false); //firefox } document.body.appendChild(tempForm); if(document.all){ tempForm.fireEvent("onsubmit",function(){ }); }else{ tempForm.dispatchEvent(new Event("submit")); } tempForm.submit(); document.body.removeChild(tempForm); } } }, error: function (XMLHttpRequest, textStatus, errorThrown) { mini.alert("加载失败!"); } }); </script>

 参考资料:https://blog.csdn.net/blacktsky/article/details/52909660

转载于:https://www.cnblogs.com/xiaoQ0725/p/9086789.html

最新回复(0)