gpt4 book ai didi

javascript - 将 javascript 变量传递给新的 php 页面

转载 作者:行者123 更新时间:2023-12-03 05:12:00 25 4
gpt4 key购买 nike

我基本上有一个用户可以输入的字符串并点击“发送”。然后这个字符串变量应该被传递到另一个打开的页面。我尝试过使用 session ,但它不起作用(第二页未加载)。这是我的代码:

首页。

<?php
session_start();
echo "<input type=\"text\" id=\"myText\">";
echo "<button onclick=\"submit()\">Submit</button>";

$_SESSION['userInput'] = $input;
?>
<script type="text/javascript">
var submit = function() {
input = document.getElementById("myText").value;
window.open ('runSecond.php','_self',false);}
</script>

第二页。

<?php
session_start();
$input = $_SESSION['userInput'];
system('./myPythonScript.py ' $input);
?>

最佳答案

第 1 页

 <?php
session_start();
echo "<input type=\"text\" id=\"myText\">";
echo "<button onclick=\"submit()\">Submit</button>";

$_SESSION['userInput'] = $input;
?>
<script type="text/javascript">
var submit = function() {
input = document.getElementById("myText").value;
window.open ('runSecond.php?userInput=' + input,'_self',false);}
</script>

第 2 页

<?php
session_start();
$input = $_GET['userInput'];
system('./myPythonScript.py ' $input);
?>

关于javascript - 将 javascript 变量传递给新的 php 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41772515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com