简体   繁体   English

提交表单并停留在与target ='_ top'相同的页面上

[英]Submit form and stay on same page with target='_top'

Here is my form on domain1: 这是我在domain1上的表格:

<form id ='myForm' action='domain2' method='GET' target='_top'>
<input type='hidden' name='id' value='00345897'>
<input type='hidden' name='status' value='Success'>
<input type="submit" value="Submit">
</form>

Now when I submit my form it goes to the domain2 as mentioned in the action. 现在,当我提交表单时,它会转到操作中提到的domain2。 Is it possible to get the response back to domain1? 是否可以将响应返回到domain1? I am getting the response if the target attribute is '_self' or if I remove the target attribute. 如果目标属性是“ _self”或删除目标属性,我会得到响应。 But with target='_top' the page is redirected to domain2. 但是使用target ='_ top'时,页面将重定向到domain2。 How can I get the response back to domain1? 如何将响应返回到domain1? Thanks. 谢谢。

The response can't go anywhere other than to the browser making the response. 响应只能传递到浏览器做出响应的任何地方。

If you don't specify a target , then it will appear in the same window or frame as the page with the form on it (replacing the page with the form on it). 如果您未指定target ,那么它将与包含表单的页面显示在同一窗口或框架中(用表单替换页面)。

If you specify target="_top" then it will appear in the top-level frame replacing that. 如果您指定target="_top" ,它将出现在顶层框架中,并替换掉它。

If you want to get the data to the site making the request then you need to either: 如果要将数据发送到发出请求的站点,则需要执行以下任一操作:

  • Make the HTTP request from domain1's server and not from a browser or 从domain1的服务器发出HTTP请求,而不是从浏览器
  • Use Ajax to make the request to domain1 (dealing with cross origin issues ) and then use JavaScript to send the data to domain1. 使用Ajax向domain1发出请求(处理跨源问题 ),然后使用JavaScript将数据发送到domain1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM