douyiken0968 2017-09-02 17:48
浏览 142
已采纳

php $ _REQUEST []不起作用

i have form in html file , it's file body

<form action="" method="post">       
    <input id="name" type="text" name="username" placeholder="username" required></br></br>
    <input id="password" type="password" name="password" placeholder="password" required></br></br>
    <p id="warn"></p></br></br>
    <input type="submit" value="Login" onclick="f()"></br>
</form>

<script>
function f() {
    var name = document.getElementById("name").value ;
    var password = document.getElementById("password").value ;
    var xttp = new XMLHttpRequest();
    xttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("warn").innerHTML = this.responseText ;             
        }
    };

    xttp.open("GET", "tst1.php?name="+name+"& password"+password, true);
    xttp.send();
}
</script>

and i have php file callled tst1.php

<?php 
    echo $_REQUEST["name"]+"...."+$_REQUEST["password"] 
?>

im trying to use ajax to show the entered value below them in p tag with id="warn" but it dose not show it

  • 写回答

2条回答 默认 最新

  • dongming4994 2017-09-02 18:01
    关注

    There are few things you need to change in your code, such as:

    • echo $_REQUEST["name"]+"...."+$_REQUEST["password"], + is not a concatenation operator, . is. So this statement should be like this:

      echo $_REQUEST["name"] . "...." . $_REQUEST["password"]; 
      
    • Missing = sign after password in this statement, xttp.open("GET", "tst1.php?name="+name+"& password"+password, true);. This statement should be like this:

      xttp.open("GET", "post.php?name="+name+"&password="+password, true);
      
    • Return false immediately after calling f() function, otherwise the page would refresh and you won't be able to see the output value here <p id="warn"></p>.

      <input ... onclick="f(); return false;">
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办