jQuery fadeOut()在PHP echo中不起作用

jQuery fadeOut()在PHP echo中不起作用,php,jquery,fadeout,Php,Jquery,Fadeout,我整晚都在尝试、搜索、尝试、研究如何在成功登录PHP后让页面淡出,然后在淡出后成功重定向到受保护的页面 <?php session_start(); if ($_GET['login']) { // Only load the code below if the GET // variable 'login' is set. You will // set this when you submit the form if (in_array($_POST

我整晚都在尝试、搜索、尝试、研究如何在成功登录PHP后让页面淡出,然后在淡出后成功重定向到受保护的页面

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
以下是我目前所做的改动,尽管这是我一直在尝试的众多改动中最新的一个:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
链接: ournewlife.com/002/login.php

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
以及守则:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>

您缺少jquery插件和文档就绪处理程序:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
      echo "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>";
      echo "<script type='text/javascript'>";
      echo "$(function(){";
      echo "$('#ournewform').fadeOut(2222);";  
      echo "});";
      echo "</script>";
echo”“;
回声“;
回显“$(函数(){”;
echo“$('ournewform').fadeOut(2222);”;
回声“});”;
回声“;

您可以试试这样的方法

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
$(document).ready(function() {
    $('#ournewform').fadeOut(2222);
    window.location ='newpage.html';
});
在php脚本中,您可以将其分配给某个变量,如

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
<?php
$script = "$(document).ready(function() {
               $('#ournewform').fadeOut(2222);
               window.location ='newpage.html';
           });";

尝试将Javascript代码与PHP分开。如果先测试是否满足条件,然后注入javascript代码,则会更加优雅:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable
?>

<script type='text/javascript'>
      $('#ournewform').fadeOut(2222);      
</script>

<?php }
else echo "";
     // Otherwise, echo the error message
?>

$(#ournewform')。淡出(2222);

不要忘了在标题部分包含Jquery库。

要达到这一效果,需要做的是:使用ajax函数,让用户登录,并根据响应,您可以选择淡出登录框或显示错误。

我在别处寻找这个问题的答案,但没有找到什么帮助。但是,我在这里找到了一个登录脚本:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>
我仍然很难淡出,但是这个表单似乎使用了ajax等,所以它可能会有更多的用途。我正在尝试收集另一个线程上的解决方案:

<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>

回荡出来的js代码永远不会被执行;这是因为您正在回显脚本数据,然后尝试重新录制。Alos它将发出一个名为“警告:无法修改标题信息–标题已发送”的警告,在退出上述代码的回显行之后,代码将如何到达实际定义表单的行??Jquery永远找不到名为“ournewform”的元素,因此将什么也不做!如果没有必要,为什么要使用echo()?此方法不起作用。不过,谢谢你的建议。你的页面没有得到回音脚本。对不起,洁,我不知道那里发生了什么。不过,我确实试过了,但在这种情况下不起作用。对不起,Ehs4n。我试图在这里发布一些代码,但没有成功。我修改了您在这里的内容,如下所示,我得到了一个服务器错误:您可以在ournewlife.com/002/login.php上看到它
$script=
应该放在您的if语句中,因为只有在用户发布表单数据并验证后,才会重定向。还要注释
标题('Location…
,因为它是在javascript代码本身中处理的,请参见
窗口。Location
我现在正在研究它。我需要等一下服务器。谢谢您花时间。@Cheryl-如果这解决了您的问题,请接受这个答案。它确实重定向,但页面不会褪色。这个解决方案看起来不错,但当我尝试它时,我得到了一个服务器错误:这对我没有帮助。你能告诉我你犯了什么错误吗?对不起,艾斯莫夫,这是我唯一的错误。也许你会有一些以上的见解。。。?该页面现在是半可操作的:ournewlife.com/005/login.php-但是如果您使用“enter”登录,您将看到它闪烁,然后淡出并淡入(?!)。。。代码就在这里,这是迄今为止最好的工作解决方案,如果您对它有任何见解,那就太好了:pastebin.com/E0p1YQQS@Cheryl我想它正在按预期工作。我再也没有收到内部服务器错误,所以如果它能解决您的问题,请接受我的回答。正如我所说,该页面仍然无法按照预期的操作方式运行。如果你关注这个链接,你会发现它工作不正常。Jaspal,我在第一次放置它时错过了你的评论。您是否有任何关于资源的建议,为实现这一目标提供逐步指导?我没有找到。如果你有任何搜索词,这也可能会有所帮助,因为我不确定我在那里击中它的鼻子。谢谢
<?php

session_start();

if ($_GET['login']) {
     // Only load the code below if the GET
     // variable 'login' is set. You will
     // set this when you submit the form

if (in_array($_POST['entryphrase'], array('enter', 'goin', 'entrezvous', 'opensesame'))) {
         // Load code below if both username
         // and password submitted are correct

         $_SESSION['loggedin'] = 1;
          // Set session variable

          echo "<script type='text/javascript'>";
          echo "$('#ournewform').fadeOut(2222);";  
          echo "</script>";

//        header("Location: protected.php");
         exit;
         // Redirect to a protected page

     } else echo "";
     // Otherwise, echo the error message

}

?>

<form action="?login=1" method="post" id="ournewform">
    <input type="text" id="ournewlogin" name="entryphrase" class="fontface" />
</form>