javascript 使用隐藏的 iframe 提交数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8306640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:59:17  来源:igfitidea点击:

Use hidden iframe to submit data

javascriptiframeform-submit

提问by Apps

I need to submit some information to my servlet. Once I submit this information, I'll receive a PDF from the servlet based on the data. I know I can construct the URL and pass parameters to it using HTTP GET. Suppose my form data is too large.So is it possible to do this using a hidden iFrame? I'll submit the parameters using the hidden iFrame and in my servlet, I write the PDF to the response stream. Will this work? If it works can someone please suggest me how to do this?

我需要向我的 servlet 提交一些信息。提交此信息后,我将收到来自 servlet 的基于数据的 PDF。我知道我可以构造 URL 并使用 HTTP GET 将参数传递给它。假设我的表单数据太大。那么可以使用隐藏的 iFrame 来做到这一点吗?我将使用隐藏的 iFrame 提交参数,并在我的 servlet 中将 PDF 写入响应流。这会奏效吗?如果它有效,有人可以建议我如何做到这一点吗?

回答by JohnP

You'll need to set the target to the iframe you want to submit it to.

您需要将目标设置为要提交到的 iframe。

<form action='...' name='theform' target='theiframe'>
  . 
  .
  .
  <iframe name='theiframe' src='...'> 
  </iframe>
</form>

This forum post has some details : http://forums.powweb.com/showthread.php?t=77213

这个论坛帖子有一些细节:http: //forums.powweb.com/showthread.php?t=77213

回答by dhh

Hm, which way do you want to sent the data using your iframe? I think you're limited to either GET or POST there, too. Means, if your data is too large, the iframe won't help sending your data.

嗯,您想使用 iframe 以哪种方式发送数据?我认为您也仅限于 GET 或 POST 那里。意思是,如果您的数据太大,iframe 将无助于发送您的数据。

What server backend do you use? You might be able to configure the maximum size of request data (post / get).

您使用什么服务器后端?您也许能够配置请求数据的最大大小(发布/获取)。

Please have a look at this messagefor more information about this.

请查看此消息以获取更多信息。

回答by Marc Uberstein

In my eyes, using the hidden Iframe method is very old school, almost like before the great days of Ajax methods.

在我看来,使用隐藏的 Iframe 方法是非常老派的,几乎就像在 Ajax 方法的伟大时代之前一样。

You can use jquery Ajax call and serialize your full form passing all variables. Remember to check your request size in your config, in case it post reaches maximum size.

您可以使用 jquery Ajax 调用并序列化传递所有变量的完整表单。请记住在您的配置中检查您的请求大小,以防它发布达到最大大小。