在JS中模拟表单的post提交,进行页面的跳转

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jal517486222/article/details/83147761

封装为Post(URL, PARAMTERS) 函数:

 /*
*功能: 模拟form表单的提交
*参数: URL 跳转地址 PARAMTERS 参数
*/
     function Post(URL, PARAMTERS) {
         //创建form表单
         var temp_form = document.createElement("form");
         temp_form.action = URL;
         //如需打开新窗口,form的target属性要设置为'_blank'
         temp_form.target = "_self";
         temp_form.method = "post";
         temp_form.style.display = "none";
         //添加参数
         for (var item in PARAMTERS) {
             var opt = document.createElement("textarea");
             opt.name = item;
             opt.value = PARAMTERS[item];
             temp_form.appendChild(opt);
         }
         document.body.appendChild(temp_form);
         //提交数据
         temp_form.submit();
     }

调用模块:

params = {
         		'WIDsubject':'竞赛报名',
         		'money':money,
             	'body':cid
		 };
		 
Post("alipay/index.php",params);

猜你喜欢

转载自blog.csdn.net/jal517486222/article/details/83147761