提交到外部网站并将网站从重定向到另一个页面提交
我必须将页面提交到外部网站。 不是问题。
问题是外部网站显示成功消息,这不好,我需要将其提交的网站重定向到更用户友好的网站。 外部网站不会重定向,如果我将重定向页面传递给它,我认为这可能是最简单的。
无论如何,对于最简单、最省力的方法有什么建议吗? 我读到过有关 iFRAME 的内容。 还有别的办法吗?
提前致谢!
这些是静态 HTML 页面。
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?
Thanks in advance!
These are static HTML pages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您无法触及外部站点的标记。
如果它们是静态的,你就缺乏解决方案。 我经常使用 cURL 库来提供此类功能(在幕后发布到外部站点)。
您也许可以使用 iframe 和 JavaScript 来完成此操作。 将表单的目标设置为 iframe 的名称(也许使用 CSS 隐藏 iframe)。 然后,它应该提交罚款。
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).
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.
既然你说“外部网站不会重定向”,我假设你无法控制它。
这意味着我可以想到三种可能的方法。
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.
IFRAME 解决方案似乎是最简单的,但如果发生错误,您可能不会注意到。
如果提交的站点返回可预测的标记,那么 AJAX 路由会更好,因为它允许您的站点解析帖子的结果并对结果做出反应。 然而,它很容易受到禁用 JavaScript 的用户的攻击。
也许最好的解决方案是编写标记以使用 IFRAME 技术,但将“onsubmit”处理程序放在表单上。 如果启用了 JavaScript,则处理程序可以执行 AJAX 操作 - 否则 IFRAME 解决方案将启动。
只需记住在 onsubmit 属性中添加“return false”,以在启用 JavaScript 时阻止 IFRAME 提交。
The IFRAME solution seems to be the simplest but, should an error occur, you might not notice.
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.
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.
Just remember to add 'return false' to the onsubmit attribute, to prevent the IFRAME submission, when JavaScript is enabled.