通过iframe进行post跨域提交表单

<div class="col-sm-12">
  <div class="panel panel-default">
    <div class="panel-body">
      <ul class="nav nav-tabs">
        <li class="active">
          <a>配置流程</a>
        </li>
        <li>
          <a id="configComponentLink" href="$configComponentLink?serviceId=">配置组件</a>
        </li>
      </ul>
      <form id="bpmnForm" class="form-inline" action="$tpgPlatformAddress/serviceorchestration/doPost.xhtm" method="post" target="bpmnSaveTarget">
        <input type="hidden" name="action" value="/serviceorchestration/ProcessAction" />
        <input type="hidden" name="event_submit_doSaveOrUpdateFlowByAjax" value="y" />
        <input type="hidden" name="serviceId" id="serviceId" />
        <input type="hidden" name="context" id="context" />
        <input type="hidden" name="callback" value="parent.onSavedProcess">
        <div class="form-inline" style="margin: 18px 0">
          <label for="currentServiceInfo" class="control-label">所属集成服务:</label>
          <input readonly="readonly" type="text" id="currentServiceInfo" class="form-control" value="" style="min-width:400px" />
          <button type="button" id="saveProcess" class="btn btn-primary" style="margin-left:10px">保存流程</button>
        </div>
        <div class="hidden">
          <iframe name="bpmnSaveTarget" id="bpmnSaveTarget"></iframe>
        </div>
      </form>
    </div>
  </div>
</div>
<script src="$homeModule.setTarget('assets/js/jquery.js')"></script>
<script>


  function onSavedProcess(response) {
    if (response.success) {
      toast.success("保存成功,正在刷新....");
      setTimeout(function () {
        window.location.reload();
      }, 1200)
    } else {
      toastr.error(decodeURI(response.errMsg));
    }
  }


  function saveProcessData(context) {
    $("#bpmnForm").submit();
  }
</script>
<script type="text/javascript">
</script>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Web 开发,当网页包含来自不同域名的 iframe(内嵌框架)时,由于浏览器的同源策略限制,iframe 之间的直接通信会受到限制。为了实现 iframe 之间的跨域通信,可以使用 postMessage 方法。 postMessage 是一种 HTML5 提供的跨文档消息传递机制,它允许在不同窗口或 iframe 之间发送消息。通过 postMessage,可以在不同域名之间进行安全的双向通信。 使用 postMessage 进行跨域通信的步骤如下: 1. 在发送消息的页面(发送方),使用 JavaScript 调用 postMessage 方法发送消息。该方法接受两个参数:要发送的消息和接收消息的目标窗口的源(origin)。目标窗口的源可以是具体的域名、协议和端口号,或者是通配符 "*" 表示任意源。 ```javascript var targetWindow = document.getElementById('target-frame').contentWindow; targetWindow.postMessage('Hello', 'https://target-domain.com'); ``` 2. 在接收消息的页面(接收方),监听 message 事件,通过 event.data 获取接收到的消息。在事件处理程序可以对消息进行处理。 ```javascript window.addEventListener('message', function(event) { if (event.origin === 'https://source-domain.com') { console.log('Received message: ' + event.data); } }); ``` 通过这种方式,发送方和接收方可以进行跨域通信,并且可以在消息传递复杂的数据结构。但要注意,为了确保安全性,应该在接收方对来自不同源的消息进行验证,以防止恶意代码的攻击。 需要注意的是,postMessage 方法只能在现代浏览器使用,兼容性可能会有所差异。此外,在使用 postMessage 进行跨域通信时,也需要确保目标窗口(接收方)支持 postMessage 方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值