JS使用POST方式跳转HTML页面

  • Post author:
  • Post category:其他


模拟FORM表单来提交POST请求

JS方法:

<script>
    function JumpPost(){
        var data = {"name":"tony","userId":"123456","type":"1"}
        jspost("http://127.0.0.1:8080/hello",data);
    }
    function jspost(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
		temp.method = "post";
        //如需新打开窗口 form 的target属性要设置为'_blank'
        //temp.target = "_blank";
		temp.style.display = "none";
		for (var x in PARAMS) {
			var opt = document.createElement("textarea");
			opt.name = x;
			opt.value = PARAMS[x];
			temp.appendChild(opt);
		}
		document.body.appendChild(temp);
        temp.submit();
        return temp;
    }
</script>

HTML:

<body>
	<script language="javascript"> JumpPost() </script>
</body>



版权声明:本文为watson2017原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。