繁体   English   中英

将javascript变量(字符串)值“转换”为PHP变量

[英]“Converting” javascript variable (String) value into PHP variable

我正在使用window.open()方法打开一个新窗口,并使用localStorage.setItem()方法传递Javascript变量(字符串)。 在打开的新窗口中,我使用localStorage.getItem()方法检索传递的变量。 现在,对于使用PHP的SQL查询,我需要此变量,例如“从表名中选择行名WHERE id = TheJSVariable”

但是我找不到任何解决方案。

有什么建议么? 谢谢

使用window.open打开时,可以将参数添加为通用的get参数。 即:

window.open(“ mysite.com/page.php?param=123”);

然后在page.php中,您可以使用以下命令读取param值:

$param = $_GET['param'];

更新:

如果要发出发布请求,则可以添加(隐藏)表单,该表单的表单字段包含要传递的值,并通过代码提交该表单。 就像是:

<form id="TheForm" method="post" action="test.asp" target="TheWindow">
<input type="hidden" name="something" value="something" />
<input type="hidden" name="more" value="something" />
<input type="hidden" name="other" value="something" />
</form>

<script type="text/javascript">
window.open('', 'TheWindow');
document.getElementById('TheForm').submit();
</script>

Window.open和通过post方法传递参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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