Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用javascript获取上一个表单POST变量? 客户端转到example.com/form.html,其中显示一个html POST表单 客户端使用特定信息填写表单,并将其提交到example.com/form.html_Javascript_Ajax_Iframe_Frameset Iframe - Fatal编程技术网

是否可以使用javascript获取上一个表单POST变量? 客户端转到example.com/form.html,其中显示一个html POST表单 客户端使用特定信息填写表单,并将其提交到example.com/form.html

是否可以使用javascript获取上一个表单POST变量? 客户端转到example.com/form.html,其中显示一个html POST表单 客户端使用特定信息填写表单,并将其提交到example.com/form.html,javascript,ajax,iframe,frameset-iframe,Javascript,Ajax,Iframe,Frameset Iframe,当example.com/form.html收到POST请求时,会在example.com/redirected.html上重定向客户端 是否可以使用javascript检索客户端填写并发布到example.com/form的变量?仅在example.com/redirected.html上部署的javaScript。我想可能会涉及到一些后台控件iFrame和ajax,但我还没有找到可靠的解决方案 操作将在同一个域上进行,因此不涉及跨域问题 不,我认为这是不可能的 你要么 将发布的值存储在coo

当example.com/form.html收到POST请求时,会在example.com/redirected.html上重定向客户端 是否可以使用javascript检索客户端填写并发布到example.com/form的变量?仅在example.com/redirected.html上部署的javaScript。我想可能会涉及到一些后台控件iFrame和ajax,但我还没有找到可靠的解决方案

操作将在同一个域上进行,因此不涉及跨域问题


不,我认为这是不可能的

你要么

将发布的值存储在cookie中 将发布的值存储在服务器端的会话变量中 将发布的值作为GET参数添加到新URL 使用GET发布原始表单,并痛苦地从新页面上的document.referer中提取发布值 对于HTML5,请使用。答案描述了如何在localstorage中存储对象——您可以在其中存储表单字段的对象

但是您必须将使用js发布的数据存储在example.com/form.html上,然后才能在example.com/redirected.html上获取数据。如果form.html中没有js,那么使用此方法是不可能的


如果您计划使用html5,并且不在其中存储太多数据,则可以使用此功能。iirc根据浏览器的不同,它有5-10mb的限制。

我认为使用纯html没有办法做到这一点。使用诸如PHP之类的服务器端语言,可以毫无问题地完成

我以前也遇到过类似的情况,我将数据提供给JS的方法是在使用PHP准备输出时将数据包含在标记中

假设重定向到php脚本从它被重定向到的脚本接收POST数据。我将在php代码中包含以下内容:

<?php
  echo '<script type="text/javascript">';
  echo 'var postData = '.json_encode($_POST).';';
  echo '</script>'
?>
如果未将POST数据传递到重定向到脚本,并且未检查是否自动发生此情况,则可以在第一个php脚本中的$\u会话变量中写入$\u POST数据:

<?php
  $_SESSION['postdata']=$_POST;
?>
然后从重定向到脚本的会话中获取它

<?php
  $postdata = $_SESSION['postdata']; //use this to create the inline script in the html
  unset($_SESSION['postdata']; //empty this from the SESSION variables
?>

您可以将这些值存储在cookie中。我不知道这是否是最好的方法。cookies是不允许的,所以我不使用cookies方法
<?php
  $postdata = $_SESSION['postdata']; //use this to create the inline script in the html
  unset($_SESSION['postdata']; //empty this from the SESSION variables
?>