【问题标题】:transferring php form data to a js window将php表单数据传输到js窗口
【发布时间】:2013-10-20 02:02:19
【问题描述】:

我正在使用 javascript 和 jquery 设计游戏。在我的游戏中,当玩家与另一个角色交谈时,它会使用 window.open('') 函数将文本作为外部文件打开。在游戏开始时,用户必须为他们的角色输入一个名称,然后由 php 处理:
<form action="play.php" method="get">
<input type="text" name="name"/><input type="submit" value="confirm"/>
</form>
.
正如我之前所说,当一个玩家与另一个玩家交谈时,它会打开外部文件,但我要问的是如何将表单数据传输到用window.open('') 打开的外部窗口我已经尝试过
function txtone()
{
window.open('txtone.php?name=<?php echo $_GET["name']; ?>')
}

但它没有用。所以基本上我最后想要的是一个用window.open('txtone.php')打开的外部窗口,它可以从它打开的页面接收php数据
(而不是打开txtone.php它会打开txtone.php?name=example )。

编辑:我有一个想法,我可以将一个 php 变量发送到使用 window.open 打开的子窗口,但我不知道如何使用window.opener 来做这个mabye?

【问题讨论】:

    标签: javascript php jquery forms window.open


    【解决方案1】:

    你试过window.open('txtone.php?name=&lt;?php echo htmlspecialchars($_GET["name"]); ?&gt;')

    【讨论】:

      【解决方案2】:
      function txtone() {
          window.open('txtone.php?name=<?= $_GET["name"] ?>');
      }
      

      【讨论】:

      • 这把我带到了 txtone.php?name==%20$_GET["name"]%20?>。
      【解决方案3】:

      当用户在游戏开始时使用他的用户名“登录”时,也许可以尝试将用户名保存在 Cookie 中,并在他想与其他人交谈时读取它并将他的名字提供给window.open 用JS。

      window.open('txtone.php<?php echo $_GET["name'}; ?>')
      

      ^该行末尾有一个错字(} 而不是]),也会导致以下结果:

      txtone.phpSomeUserName
      

      您缺少那里的参数(如果您的代码中有这样的参数,很可能是您的罪魁祸首)。可能你打算有类似的东西

      txtone.php?username=<?php echo "someUsername"; ?>
      

      【讨论】:

        【解决方案4】:

        你的代码有点不对

        改变

        window.open('txtone.php<?php echo $_GET["name'}; ?>')
        

        window.open('txtone.php<?php echo $_GET['name']; ?>')
        

        还要确保您将值传递给您的姓名输入

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-12
          • 1970-01-01
          • 2014-03-06
          • 1970-01-01
          • 1970-01-01
          • 2023-03-21
          • 2014-12-31
          • 2015-11-13
          相关资源
          最近更新 更多