[英]“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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.