JS使用POST方式跳转HTML页面

模拟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>

猜你喜欢

转载自blog.csdn.net/watson2017/article/details/125912800