I have to have a page submit to an external website. Not a problem.
我必须将页面提交到外部网站。不是问题。
Problem is the external website displays a successful message, not good, I need to get the site it was submitted from to be redirected to something more user friendly. The external website won't redirect, which I think might be the easiest, if I pass it a redirectto page.
问题是外部网站显示成功的消息,不好,我需要从提交的网站获得重定向到更加用户友好的东西。如果我将其重定向到页面,外部网站将不会重定向,我认为这可能是最简单的。
Anyway, any suggestions for the easiest and less effort approach to this? I read about having an iFRAME. Is there another way?
无论如何,对于最简单和最省力的方法有什么建议吗?我读过有关iFRAME的内容。还有另一种方式吗?
Thanks in advance!
提前致谢!
These are static HTML pages.
这些是静态HTML页面。
3 个解决方案
#1
I'm assuming you can't touch the markup of the external site.
我假设你无法触及外部网站的标记。
If they're static you're short of solutions. I've often used the cURL library to provide this sort of functionality (posting to the external site behind the scenes).
如果它们是静态的,那么你就缺乏解决方案。我经常使用cURL库来提供这种功能(在幕后发布到外部站点)。
You might be able to do it with an iframe and JavaScript. Set the target of your form to the name of the iframe (maybe hide the iframe using CSS). Then, it should submit fine.
您可以使用iframe和JavaScript来完成此操作。将表单的目标设置为iframe的名称(可能使用CSS隐藏iframe)。然后,它应该提交罚款。
#2
Since you say "the external site won't redirect", I'm assuming that you have no control over it.
既然你说“外部网站不会重定向”,我假设你无法控制它。
This means that you have three possible approaches that I can think of.
这意味着您可以考虑三种可能的方法。
- Proxy the request via your own server. This is the safe option, but won't use any cookies the third party site expects from the user.
- Use an iframe and assume it will never fail (because you can't read the result). It might error or time out without you being able to compensate.
- Use a Java Applet (or similar), and have the user accept a series of scary security warnings (if they even have the Java plug-in installed)
通过您自己的服务器代理请求。这是安全选项,但不会使用第三方网站期望用户提供的任何cookie。
使用iframe并假设它永远不会失败(因为你无法读取结果)。没有你能够补偿它可能会出错或超时。
使用Java Applet(或类似的),让用户接受一系列可怕的安全警告(如果他们甚至安装了Java插件)
#3
The IFRAME solution seems to be the simplest but, should an error occur, you might not notice.
IFRAME解决方案似乎是最简单的,但如果发生错误,您可能不会注意到。
If the site that is being submitted to returns predictable markup, then the AJAX route would be preferable, as it allows your site to parse, and react to, the results of the post. It is, however, vulnerable to the user having JavaScript disabled.
如果提交的站点返回可预测的标记,那么AJAX路由将更可取,因为它允许您的站点解析并对帖子的结果作出反应。但是,它对于禁用JavaScript的用户很容易受到攻击。
Probably the best solution, is to write your markup to use the IFRAME technique, but put an 'onsubmit' handler onto the form. If JavaScript is enabled, then the handler can do the AJAX stuff - other wise the IFRAME solution will kick in.
可能最好的解决方案是编写标记以使用IFRAME技术,但在表单上放置一个“onsubmit”处理程序。如果启用了JavaScript,则处理程序可以执行AJAX操作 - 否则IFRAME解决方案将启动。
Just remember to add 'return false' to the onsubmit attribute, to prevent the IFRAME submission, when JavaScript is enabled.
只需记住在onsubmit属性中添加'return false',以防止在启用JavaScript时提交IFRAME。
<form action="http://external.server/submission.html"
target="id_of_your_IFRAME"
onsubmit="submitViaAJAX(); return false">
... form fields ...
</form>
#1
I'm assuming you can't touch the markup of the external site.
我假设你无法触及外部网站的标记。
If they're static you're short of solutions. I've often used the cURL library to provide this sort of functionality (posting to the external site behind the scenes).
如果它们是静态的,那么你就缺乏解决方案。我经常使用cURL库来提供这种功能(在幕后发布到外部站点)。
You might be able to do it with an iframe and JavaScript. Set the target of your form to the name of the iframe (maybe hide the iframe using CSS). Then, it should submit fine.
您可以使用iframe和JavaScript来完成此操作。将表单的目标设置为iframe的名称(可能使用CSS隐藏iframe)。然后,它应该提交罚款。
#2
Since you say "the external site won't redirect", I'm assuming that you have no control over it.
既然你说“外部网站不会重定向”,我假设你无法控制它。
This means that you have three possible approaches that I can think of.
这意味着您可以考虑三种可能的方法。
- Proxy the request via your own server. This is the safe option, but won't use any cookies the third party site expects from the user.
- Use an iframe and assume it will never fail (because you can't read the result). It might error or time out without you being able to compensate.
- Use a Java Applet (or similar), and have the user accept a series of scary security warnings (if they even have the Java plug-in installed)
通过您自己的服务器代理请求。这是安全选项,但不会使用第三方网站期望用户提供的任何cookie。
使用iframe并假设它永远不会失败(因为你无法读取结果)。没有你能够补偿它可能会出错或超时。
使用Java Applet(或类似的),让用户接受一系列可怕的安全警告(如果他们甚至安装了Java插件)
#3
The IFRAME solution seems to be the simplest but, should an error occur, you might not notice.
IFRAME解决方案似乎是最简单的,但如果发生错误,您可能不会注意到。
If the site that is being submitted to returns predictable markup, then the AJAX route would be preferable, as it allows your site to parse, and react to, the results of the post. It is, however, vulnerable to the user having JavaScript disabled.
如果提交的站点返回可预测的标记,那么AJAX路由将更可取,因为它允许您的站点解析并对帖子的结果作出反应。但是,它对于禁用JavaScript的用户很容易受到攻击。
Probably the best solution, is to write your markup to use the IFRAME technique, but put an 'onsubmit' handler onto the form. If JavaScript is enabled, then the handler can do the AJAX stuff - other wise the IFRAME solution will kick in.
可能最好的解决方案是编写标记以使用IFRAME技术,但在表单上放置一个“onsubmit”处理程序。如果启用了JavaScript,则处理程序可以执行AJAX操作 - 否则IFRAME解决方案将启动。
Just remember to add 'return false' to the onsubmit attribute, to prevent the IFRAME submission, when JavaScript is enabled.
只需记住在onsubmit属性中添加'return false',以防止在启用JavaScript时提交IFRAME。
<form action="http://external.server/submission.html"
target="id_of_your_IFRAME"
onsubmit="submitViaAJAX(); return false">
... form fields ...
</form>