Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $\u POST无法在PHP中工作。也尝试了$u请求_Javascript_Php_Html - Fatal编程技术网

Javascript $\u POST无法在PHP中工作。也尝试了$u请求

Javascript $\u POST无法在PHP中工作。也尝试了$u请求,javascript,php,html,Javascript,Php,Html,这是我的HTML <form class="login-form" method="POST"> <input type="password" placeholder="password" id="password" name="password"/> <input type="button" id="login" name="login" value="login" onclick="redirect()"></inpu

这是我的HTML

   <form class="login-form" method="POST"> 
      <input type="password" placeholder="password" id="password" name="password"/>
      <input type="button" id="login" name="login" value="login" onclick="redirect()"></input>
        </form>

还有我的JS

         <script type="text/javascript">
        $(document).ready(function redirect(){
        $("#login").click(function(){
        var pwd="<?php echo $pwd?>";
        alert("<?php echo "this is pass".$pword?>");
        if(userID===user && pwd===pass)
        {
        window.location.href = 'http://localhost/Annapoorna/Welcome_Page.php';
        }
        else
      {
         alert("Please enter correct username and password!");
      }
        }
    });
});
</script>

$(文档).ready(函数重定向(){
$(“#登录”)。单击(函数(){
var pwd=“”;
警报(“”);
if(userID==user&&pwd==pass)
{
window.location.href=http://localhost/Annapoorna/Welcome_Page.php';
}
其他的
{
警报(“请输入正确的用户名和密码!”);
}
}
});
});
和PHP

 <?php
     $username="";
     $pwd="";
     $pword="";
     function confirm(){


        if(isset($_REQUEST['password']))
        {
            $pword = $_REQUEST['password'];
        }

        $sth->execute(array(':pass'=>$pword));
        foreach ($sth->fetchAll() as $row) {
        $username=$row['username'];
        $pwd=$row['password'];
        echo $pword;
        }
   ?>     


$\u POST未返回任何值。已尝试$u请求,但无效。还为密码字段分配了ID和名称。

您没有提交表单,只是将用户重定向到该页面。试试这个

<form id='myForm' class="login-form" method="POST" action='/Annapoorna/Welcome_Page.php'> 
  <input type="password" placeholder="password" id="password" name="password"/>
  <input type="button" id="login" name="login" value="login" onclick="redirect()"></input>
    </form>

在javascript中

 <script type="text/javascript">
    $(document).ready(function redirect(){
    $("#login").click(function(){
    var pwd="<?php echo $pwd?>";
    alert("<?php echo "this is pass".$pword?>");
    if(userID===user && pwd===pass)
    {
     $('#myForm').submit();
    }
    else
  {
     alert("Please enter correct username and password!");
  }
    }
});

$(文档).ready(函数重定向(){
$(“#登录”)。单击(函数(){
var pwd=“”;
警报(“”);
if(userID==user&&pwd==pass)
{
$('#myForm')。提交();
}
其他的
{
警报(“请输入正确的用户名和密码!”);
}
}
});
}));

window.location.href=http://localhost/Annapoorna/Welcome_Page.php';参数在哪里?提交表单或向URL添加参数。不仅仅是重定向嘿,页面打开了。所以这里没有问题。页面将打开,参数在哪里?您没有传递您需要传递的参数,如:
window.location.href=http://localhost/Annapoorna/Welcome_Page.php?id=123&password=test“
;我不需要$_POST应该在警报框中返回一些内容。与下一页无关。警报框中显示了什么?我很担心警报(“”);警告框中有文本“this is pass”,您必须在代码中检查$pword,因为它不在本代码段中,如果它完成了您的工作,还应将答案标记为绿色。它不在哪个代码中?它在JS和PHP中都有。