javascript解决单点登录(get或post方式)

xiaoxiao2024-04-21  34

单点登录用get方式很简单,用url拼接就可以了,比如“http://www.baidu.com/s?wd=java”,这个url就向百度提交了关键字java,获得查询结果。

但是如果服务器只接受,或只处理了‘post’方式的参数怎么办(百度好像只处理了get)。

下面这段代码用一个动态的表单,动态改变它的action,method等属性,并动态的生成其子结点,达到提交参数的效果。

openPage方法有三个参数,第一个是要提交的url,也就是action属性的值,第二个是提交方式(get or post),第三个是提交参数用一个json数组表示也来,以便后面迭代生成hidden(隐藏域)。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>post and get form submit</title> <script language="javascript"> function openPage(url,method,params){ var dynamicForm = document.getElementById("dynamicForm"); dynamicForm.setAttribute("method",method); dynamicForm.setAttribute("action",url); dynamicForm.innerHTML = ""; for(var i=0;i<params.length;i++){ var input = document.createElement("input"); input.setAttribute("type","hidden"); input.setAttribute("name",params[i].paramName); input.setAttribute("value",params[i].paramValue); dynamicForm.appendChild(input); } dynamicForm.submit(); } </script> </head> <body> <div id="formDiv"> <form id="dynamicForm" target="_blank"> </form> </div> <p><a href="javascript:openPage('http://www.iteye.com/search','get',[{paramName:'query',paramValue:'struts'},{paramName:'type',paramValue:'topic'}]);">click1</a></p> <p><a href="javascript:openPage('http://www.iteye.com/search','post',[{paramName:'query',paramValue:'spring'},{paramName:'type',paramValue:'topic'}]);">click2</a></p> <p><a href="javascript:alert(&quot;哈哈&quot;);">click3</a></p> </body> </html>

经过测试,baidu、google只接受get方式提交参数。

而javaeye网站两种方式都经过处理了。

相关资源:网易rsa加密post登录js
转载请注明原文地址: https://www.6miu.com/read-5015141.html

最新回复(0)