zoukankan      html  css  js  c++  java
  • url参数过长处理办法

    常用的解决办法是将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

  • 相关阅读:
    P1082 同余方程
    P2678 跳石头
    P2827 蚯蚓
    P1351 联合权值
    P2822 组合数问题
    P3958 奶酪
    P2296 寻找道路
    P2661 信息传递
    平时问题总结
    平时总结
  • 原文地址:https://www.cnblogs.com/xiaoQ0725/p/9086789.html
Copyright © 2011-2022 走看看