打开一个新页面 并向新页面发送一个POST请求 新页面并不是自己的页面,而是别人的

当前有一个场景,需要PHP处理完逻辑后,调转到一个别人的新页面,并在此新页面发送一个POST请求。于是乎到处百度  

网上找来的资料,做下整理 

//模拟表单post提交,且打开新页面跳转

 function post(URL, PARAMS) { 
      var temp_form = document.createElement("form");      
      temp_form .action = URL;      
      temp_form .target = "_blank";
      temp_form .method = "post";      
      temp_form .style.display = "none"; 
      for (var x in PARAMS) { 
        var opt = document.createElement("textarea");      
          opt.name = x;      
          opt.value = PARAMS[x];      
          temp_form .appendChild(opt);      
      }      
      document.body.appendChild(temp_form);      
      temp_form .submit();     
  }

  //  使用方法url表示请求地址,后面传参类似ajax
post('url',{id:id,name:name,age:age});

以上代码  完美解决此问题。

posted @   树下水月  阅读(244)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示