常用的解決辦法是將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