简体   繁体   中英

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

Here is my form on 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. Is it possible to get the response back to domain1? I am getting the response if the target attribute is '_self' or if I remove the target attribute. But with target='_top' the page is redirected to domain2. How can I get the response back to 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).

If you specify target="_top" then it will appear in the top-level frame replacing that.

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
  • Use Ajax to make the request to domain1 (dealing with cross origin issues ) and then use JavaScript to send the data to domain1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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