douyimin1083 2017-11-14 09:33
浏览 42
已采纳

如何重新加载页面并使用PHP + JS显示查询参数?

function myfun()
{
  var nm=12;
  window.location.href="bkd.php?uid="+nm;
}

<form name="frm" method="GET">
  <input type="text" value="ghf" onclick="myfun();"></input>
  <input type="hidden" value="" name="txtval" id="txtval"></input>
  <?php 
    echo $_GET["uid"];
  ?>
</form>

I have added JS and HTML on the same page. Wwhen I execute the code I am getting the value in PHP but it also displays

"Undefined index: uid"

  • 写回答

1条回答 默认 最新

  • dongtan9465 2017-11-14 09:36
    关注

    The first time you load the page $_GET['uid'] might not be set so you need to check it. You can use array_key_exists() for this.

    I would also recommend putting the onclick action on a button rather than the text field.

    function myfun()
    {
        var nm=12;
        window.location.href="bkd.php?uid="+nm;
    }
    
    <form name="frm" method="GET">
    <input type="text" value="ghf"></input>
    <input type="hidden" value="" name="txtval" id="txtval"></input>
    <input type="button" onclick="myfun();"></input>
    <?php
    if (array_key_exists("uid", $_GET)) { 
        echo $_GET["uid"];
    }
    
    ?>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?