您当前的位置: 首页 >  html

培根芝士

暂无认证

  • 1浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JS使用POST方式跳转HTML页面

培根芝士 发布时间:2022-07-21 15:14:01 ,浏览量:1

模拟FORM表单来提交POST请求

 JS方法:


    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;
    }

HTML: 


	 JumpPost() 

关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.0366s